hpilo

Chapter2_SyntaxB_Ex2

Dec 15th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*  ==================================================
  4.          Chapter 2: Syntax section B- Loops
  5.  
  6.              Ex2: Display amount of Odd input
  7.     ===================================================
  8. */
  9.  
  10. public class MyProgram {
  11.     public static void main(String[] args) {
  12.  
  13.         //variables
  14.         final int SIZE=10;  //represent max input
  15.         int number;
  16.         int counter=0;      //represent the amount of Odd input
  17.         Scanner s=new Scanner(System.in);
  18.  
  19.         System.out.println("Enter "+SIZE+" numbers: ");
  20.  
  21.         //loop until SIZE input
  22.         for(int i=0;i<SIZE;i++){
  23.             number=s.nextInt();
  24.             if(number%2!=0)         //check if number is odd, increase counter accordingly
  25.                 counter++;
  26.         }
  27.  
  28.         //display amount of odd input
  29.         System.out.println(counter+ " Odd numbers");
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment