Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /* ==================================================
- Chapter 2: Syntax section B- Loops
- Ex2: Display amount of Odd input
- ===================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- final int SIZE=10; //represent max input
- int number;
- int counter=0; //represent the amount of Odd input
- Scanner s=new Scanner(System.in);
- System.out.println("Enter "+SIZE+" numbers: ");
- //loop until SIZE input
- for(int i=0;i<SIZE;i++){
- number=s.nextInt();
- if(number%2!=0) //check if number is odd, increase counter accordingly
- counter++;
- }
- //display amount of odd input
- System.out.println(counter+ " Odd numbers");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment