Input 10 number check all are even or not using for loop in Java
for Loop - Question 7
In this question, we will see how to input 10 numbers and check whether all the entered numbers are even numbers only or not in Java programming using for loop. To know more about for loop click on the for loop lesson.
Q7) Write a program in Java to input 10 numbers and check whether all the entered numbers are even numbers only or not using for loop.
Program
import java.util.Scanner;
public class Q7
{
public static void main(String args[])
{
int i,n,ec=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter 10 numbers");
for(i=1; i<=10; i=i+1)
{
n=sc.nextInt();
if(n%2==0)
{
ec=ec+1; // counting the even numbers
}
}
if(ec==10)
{
System.out.println("All numbers are even");
}
else
{
System.out.println("All numbers are not even");
}
}
}
Output
Enter 10 numbers 2 8 6 12 18 36 24 4 48 90 All numbers are even