Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package myApp;
- import java.util.Scanner;
- public class class03_ex07 {
- public static void main(String[] args) {
- //init vars
- final int TIMES = 5;
- int n = 0,
- count = 0;
- //open in_stream
- Scanner s = new Scanner(System.in);
- //usage info
- System.out.printf("Type in %d numbers (Integer type): ", TIMES);
- //loop x times
- while (count != TIMES) {
- n = s.nextInt();
- //if the number is even
- if (n%2 == 0) {
- count += 1; //raise count by 1
- //style usr msg for edge cases
- if ((TIMES-count) != 0) { System.out.printf("%d intercepted. %d more to go..%n", n, TIMES-count); }
- else { System.out.printf("%d intercepted. ", n); }
- }
- }
- //close in_stream
- s.close();
- //exit msg
- System.out.printf("Done. %n%d even numbers recieved.", TIMES);
- }
- }
Add Comment
Please, Sign In to add comment