The aim of the following program is to count all odd numbers given by the user. The
program should display how many odd numbers the user has entered. The code
written below displays the number of odd integers for each new entry. How to
change this code in order to display the number of odd integers only at the end?
Scanner input = new Scanner(System.in);
int count = 0;
for(int i = 0 ; i <20 ; i++){
System.out.print("Enter a number: ");
int n = input.nextInt();
if(n % 2 != 0)
count++;
System.out.println("the number of odd integers is " + count);
}
Answers
Answered by
0
Answer:
Scanner input = new Scanner(System.in);
int count = 0;
for(int i = 0 ; i <20 ; i++){
System.out.print("Enter a number: ");
int n = input.nextInt();
if(n % 2 != 0)
count++;
}
System.out.println("the number of odd integers is " + count);
Similar questions
English,
5 months ago
Math,
5 months ago
India Languages,
5 months ago
Math,
10 months ago
Social Sciences,
10 months ago
Math,
1 year ago