Computer Science, asked by 21730676, 10 months ago

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 srajfaroquee
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