Advertisement
Shailrshah

Counting the Number of Uppercases, Lowercases and spaces

Dec 19th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.io.IOException;
  4. class testHello{
  5.         public static void main(String args[]) throws IOException{
  6.                 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  7.                 System.out.println("Enter a string");
  8.                 String input = br.readLine();
  9.                 int upper = 0, lower = 0, blank = 0, other = 0;
  10.                 for(int i = 0; i < input.length(); i++){
  11.                         if(input.charAt(i) == ' ') blank++;
  12.                         else if(input.charAt(i) >= 65 && input.charAt(i) <= 90) upper++;
  13.                         else if(input.charAt(i) >= 97 && input.charAt(i) <= 122 ) lower++;
  14.                         else other++;
  15.                 }
  16.                 System.out.print("\nUpper: "+upper +"\nLower: " +lower +"\nBlank: " +blank);
  17.                 System.out.print("\nOther: " +other +"\nTotal: "+(upper+lower+blank+other));
  18.         }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement