user will input a set of integers until 0 is input. When each number is input, output whether the number input is it even or odd. Additionally, count the even numbers input. When 0 is input, output the count of the even numbers. Write the code here including the class definition and main function:
Answer:-
Program:-
import java.util.Scanner;
public class evencount {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n,count=0,even=0;
n=sc.nextInt();
while(n!=0){
count++;
if(n%2==0){
even=even+1;
System.out.println(n+" is an Even Number");
}
else
System.out.println(n+"is an Odd Number");
n=sc.nextInt();
}
if(count!=0){
System.out.println("the count of Total numbers is:"+count);
System.out.println("the count of even numbers is:"+even);
}
else
System.out.println("No Data entered");
}
}
input :- 1 2 3 4 5 6 7 8 0
Output :-
1 is an Odd Number
2 is an Even Number
3 is an Odd Number
4 is an Even Number
5 is an Odd Number
6 is an Even Number
7 is an Odd Number
8 is an Even Number
the count of total numbers is :8
the count of even numbers is:4
If you have any doubt in this answer please comment your query. If it is helpful please upvote.
Get Answers For Free
Most questions answered within 1 hours.