write a program in Java to accept 10 numbers in one dimensional array and find even number ?
Answers
★
import java.util.Scanner; // We import Scanner class.
public class Main { // Class name is called as Main.
public static void main(String[] args) { // Main method.
Scanner input = new Scanner(System.in); // Scanner Activation.
int[] numbers = new int[10]; // Array of ten elements created.
System.out.println("Enter 10 numbers:"); // Printing a string that asks for input.
for (int i = 0; i < numbers.length; i++) { // Loop till 10 so that it accepts 10 numbers.
numbers[i] = input.nextInt(); // We take input in numbers[i]. The value of i keeps changing.
} // End of for loop.
System.out.println("Even numbers:"); // A sentence that declares the even numbers.
for (int i = 0; i < numbers.length; i++) { // Another for loop to check the even numbers.
if (numbers[i] % 2 == 0) { // If statement that checks if the number is even.
System.out.print(numbers[i] + " "); // Statement.
} // End of if block.
} // End of for loop.
} // End of Main Method.
} // End of class.