fork(1) download
  1. import java.util.*;
  2.  
  3. class WsCube {
  4. public static void main(String[] args) {
  5. String str = "JAvaProGramming";
  6.  
  7. // Array store the frequency of
  8. // each character
  9. int[] count = new int[52];
  10.  
  11. // Loop through string and
  12. for (char ch : str.toCharArray()) {
  13.  
  14. // Update count at index (char - 'a')
  15. if((int)ch >= 97 && (int)ch <= 122){
  16. count[ch - 'a']++;
  17. }
  18.  
  19. if((int)ch >= 65 && (int)ch <= 90){
  20.  
  21. // Update count at index (char - 'A')
  22. int temp = ch -'A';
  23. count[temp + 25]++;
  24. }
  25. }
  26.  
  27. // Print characters which occurred
  28. for (int i = 0; i < 52; i++) {
  29. if (count[i] > 0 && i <= 25) {
  30. System.out.println((char)(i + 'a') + " : "
  31. + count[i]);
  32. }
  33. if (count[i] > 0 && i > 25) {
  34. int temp = i - 25;
  35. System.out.println((char)(temp + 'A') + " : "
  36. + count[i]);
  37. }
  38.  
  39. }
  40. }
  41. }
Success #stdin #stdout 0.15s 57452KB
stdin
Standard input is empty
stdout
a : 2
g : 1
i : 1
m : 2
n : 1
o : 1
r : 2
v : 1
z : 1
G : 1
J : 1
P : 1