hpilo

Chapter2_SyntaxB_Ex4

Dec 15th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*  ==================================================
  4.          Chapter 2: Syntax section B- Loops
  5.  
  6.            Ex4: Display amount of lower-case
  7.     ===================================================
  8. */
  9.  
  10. public class MyProgram {
  11.     public static void main(String[] args) {
  12.  
  13.         //variables
  14.         final int SIZE=10;  //represent max input
  15.         char letter;
  16.         int counter=0;  //represent the amount of lower case input
  17.         Scanner s=new Scanner(System.in);
  18.  
  19.         System.out.println("Enter 10 letters: ");
  20.  
  21.         //loop until SIZE input
  22.         for(int i=0;i<SIZE;i++){
  23.             letter=s.next().charAt(0);
  24.             if(letter>='a' && letter<='z')   //check if lower-case letter, increase counter accordingly
  25.                 counter++;
  26.         }
  27.  
  28.         //display amount of lower-case input
  29.         System.out.println(counter+" lower-case letters!\nEnd");
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment