fork(1) 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.  
  11.  
  12. final static int AlphabetSize = 26;
  13. final static Scanner cin = new Scanner(System.in);
  14. final static PrintStream cout = System.out;
  15. final static int MaxBarLength = 50;
  16.  
  17. public static void main(String[] args) {
  18. try {
  19. processFile();
  20. }
  21. catch (IOException e) {
  22. e.printStackTrace();
  23. } // end try
  24. } // end main
  25.  
  26. static void processFile() throws FileNotFoundException, IOException {
  27. InputStream inFile = System.in;
  28. int inputValue;
  29.  
  30. // declare other variables you need
  31. int counters [] = new int [26];
  32.  
  33. // get the first character from file
  34. inputValue = inFile.read();
  35. while (inputValue != -1) {
  36. char ch = (char) inputValue;
  37.  
  38. // add code to process this character
  39. if (ch >= 'a' && ch <= 'z'){
  40. counters[ch - 'a']++;
  41. }
  42.  
  43. // read next input character
  44. inputValue = inFile.read();
  45. } // end loop
  46.  
  47. inFile.close();
  48.  
  49. // generate appropriate output
  50. display(counters);
  51.  
  52. } // end function
  53.  
  54. static void display(final int [] counters) {
  55. // write code for this function
  56.  
  57. System.out.println("Letter" + " " + "Count");
  58. System.out.println("------" + " " + "-----");
  59. printChars(counters);
  60. } // end function
  61.  
  62. // char2int is complete
  63. static int char2int(final char arg) {
  64. if (!Character.isLetter(arg))
  65. return -1;
  66. else
  67. return (int) Character.toUpperCase(arg) - (int) 'A';
  68. } // end function
  69.  
  70.  
  71. // function printChars writes n copies of the character c to the
  72. // standard output device
  73. static void printChars (final int[] counters) {
  74. // write the code
  75. for (int i = 0; i < 26; i++){
  76. System.out.printf("%c%7d\n", i + 'A', counters[i]);
  77. }
  78.  
  79. }
  80.  
  81.  
  82. }
Success #stdin #stdout 0.15s 321344KB
stdin
quick brown fox jumps over the lazy dog
stdout
Letter Count
------ -----
A      1
B      1
C      1
D      1
E      2
F      1
G      1
H      1
I      1
J      1
K      1
L      1
M      1
N      1
O      4
P      1
Q      1
R      2
S      1
T      1
U      2
V      1
W      1
X      1
Y      1
Z      1