fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) throws IOException
  11. {
  12. char letter;
  13. String sentence;
  14. int counter = 0;
  15. char response = 'o';
  16.  
  17. do
  18. {
  19. System.out.println("Type a sentence: ");
  20. sentence = input.readLine();
  21. System.out.println("Type a character to find: ");
  22. letter = (char) input.read();
  23.  
  24. for(int x=0;x<sentence.length();x++)
  25. {
  26. if(letter==sentence.charAt(x))
  27. {
  28. counter++;
  29. }
  30. }
  31.  
  32. System.out.println("Number of times " + letter + " occured is: " + counter);
  33. System.out.println("Continue? [y/n]: ");
  34. response = (char) input.read();
  35. System.out.println(">" + response + "<");
  36.  
  37. }while(response != 'n');
  38. }
  39. }
Runtime error #stdin #stdout #stderr 0.1s 320576KB
stdin
test
t
y
foo
f
n
stdout
Type a sentence: 
Type a character to find: 
Number of times t occured is: 2
Continue? [y/n]: 
>
<
Type a sentence: 
Type a character to find: 
Number of times f occured is: 2
Continue? [y/n]: 
>o<
Type a sentence: 
Type a character to find: 
Number of times f occured is: 2
Continue? [y/n]: 
>
<
Type a sentence: 
Type a character to find: 
Number of times ￿ occured is: 2
Continue? [y/n]: 
>￿<
Type a sentence: 
Type a character to find: 
stderr
Exception in thread "main" java.lang.NullPointerException
	at Ideone.main(Main.java:25)