Shavit

P. 56 Ex. 3

Jan 21st, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class alphabetCounter {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner(System.in);
  12.        
  13.         final int LETTERS = 26;
  14.         int[] abc = new int[LETTERS];
  15.        
  16.         System.out.println("Enter a string and end it with '*':");
  17.        
  18.         int cur = in.next().charAt(0);
  19.         while(cur != '*')
  20.         {
  21.             if(cur <= 'z' && cur >= 'a')
  22.                 abc[cur - 97]++;
  23.             cur = in.next().charAt(0);
  24.         }
  25.        
  26.         for(int i = 0; i < LETTERS; i++)
  27.             System.out.printf("%c - %d times\n", (i + 97), abc[i]);
  28.        
  29.         in.close();
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment