dm6801

20171113 - 03 - classEx_01

Nov 13th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package myApp;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class class03_ex07 {
  6.  
  7.     public static void main(String[] args) {
  8.         //init vars
  9.         final int   TIMES = 5;
  10.        
  11.         int         n = 0,
  12.                     count = 0;
  13.        
  14.         //open in_stream
  15.         Scanner s = new Scanner(System.in);
  16.        
  17.         //usage info
  18.         System.out.printf("Type in %d numbers (Integer type): ", TIMES);
  19.        
  20.         //loop x times
  21.         while (count != TIMES) {
  22.             n = s.nextInt();
  23.            
  24.             //if the number is even
  25.             if (n%2 == 0) {
  26.                 count += 1; //raise count by 1
  27.                
  28.                 //style usr msg for edge cases
  29.                 if ((TIMES-count) != 0) { System.out.printf("%d intercepted. %d more to go..%n", n, TIMES-count); }
  30.                 else { System.out.printf("%d intercepted. ", n); }
  31.                
  32.             }
  33.         }
  34.        
  35.         //close in_stream
  36.         s.close();
  37.        
  38.         //exit msg
  39.         System.out.printf("Done. %n%d even numbers recieved.", TIMES);
  40.        
  41.     }
  42.  
  43. }
Add Comment
Please, Sign In to add comment