Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /* ==================================================
- Chapter 2: Syntax section B- Loops
- Ex1: Five even numbers input
- ===================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- int number;
- int counter=0;
- Scanner s=new Scanner(System.in);
- //loop until user enter input of 5 even numbers
- do {
- //user input
- System.out.println("Enter a number: ");
- number=s.nextInt();
- //check if even, increase counter accordingly
- if(number%2==0)
- counter++;
- }
- while(counter<5);
- System.out.println("you've entered 5 even numbers!\nEnd");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment