dm6801

20171109 - 03 - classEx_02

Nov 11th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. package myApp;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class class03_02 {
  6.  
  7.     public static void main(String[] args) {
  8.         //init vars
  9.         int n       = 0,
  10.             count   = 0;
  11.        
  12.         //usage msg
  13.         System.out.println("Type 10 numbers, seperated by Enter: ");
  14.        
  15.         //open in_stream
  16.         Scanner s = new Scanner(System.in);
  17.        
  18.         //loop 10 times
  19.         for (int i=0; i<10; i++) {
  20.             n = s.nextInt();                //parse int
  21.             if (n%2 == 1) { count += 1; }   //if number is not-even, raise counter by 1
  22.         }
  23.        
  24.         //close in_stream
  25.         s.close();
  26.  
  27.         //output to user
  28.         System.out.printf("# of unEven = %d%n", count);
  29.        
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment