Advertisement
Shavit

P. 167 Ex. 7.9

Nov 3rd, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class CapitalLetterCounter {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         int listSize;
  14.         int capitalCounter = 0;
  15.         char ch;
  16.        
  17.         System.out.println("How long is your list of characters?");
  18.         listSize = in.nextInt();
  19.        
  20.         System.out.println("Enter characters:");
  21.        
  22.         for (int i = 0; i < listSize; i++)
  23.         {
  24.             ch = in.next().charAt(0);
  25.             if(ch >= 'A' && ch <= 'Z')
  26.                 capitalCounter++;
  27.         }
  28.        
  29.         System.out.printf("The number of characters that are capital letters in the English alphabet is %d.", capitalCounter);
  30.        
  31.         in.close();
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement