hpilo

Chapter2_SyntaxB_Ex1

Dec 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*  ==================================================
  4.          Chapter 2: Syntax section B- Loops
  5.  
  6.              Ex1: Five even numbers input
  7.     ===================================================
  8. */
  9.  
  10. public class MyProgram {
  11.     public static void main(String[] args) {
  12.  
  13.         //variables
  14.         int number;
  15.         int counter=0;
  16.         Scanner s=new Scanner(System.in);
  17.  
  18.         //loop until user enter input of 5 even numbers
  19.         do {
  20.  
  21.             //user input
  22.             System.out.println("Enter a number: ");
  23.             number=s.nextInt();
  24.  
  25.             //check if even, increase counter accordingly
  26.             if(number%2==0)
  27.                 counter++;
  28.         }
  29.         while(counter<5);
  30.         System.out.println("you've entered 5 even numbers!\nEnd");
  31.  
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment