Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. package edu.wit.cs.comp1000;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6. *
  7. * @author
  8. *
  9. */
  10.  
  11. public class PA7b {
  12.  
  13. /**
  14. * Program execution point: input text via console input, output counts for each
  15. * letter found in the input (case-insensitive)
  16. *
  17. * @param args command-line arguments (ignored)
  18. */
  19. public static void main(String[] args) {
  20.  
  21.  
  22. final int[] counter = new int[26];
  23. final Scanner S = new Scanner(System.in);
  24.  
  25. System.out.printf("Enter text: ");
  26.  
  27. while (S.hasNext()) {
  28. final String s = S.next();
  29. for (int i = 0; i < s.length(); i++) {
  30. final char c = s.charAt(i);
  31. if (c >= 'A' && c <= 'Z') {
  32. counter[c - 'A']++;
  33. } else if (c >= 'a' && c <= 'z') {
  34. counter[c - 'a']++;
  35. }
  36. }
  37. }
  38. boolean tfstatement = false;
  39. for (int i = 0; i < counter.length; i++) {
  40.  
  41. if (counter[i] > 0) {
  42. System.out.printf("%c: %d%n", ('A' + i), counter[i]);
  43. tfstatement = true;
  44. }
  45. }
  46. if (!tfstatement) {
  47. System.out.printf("%n");
  48. }
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement