DUET PG Score Card 2021
NHAI Recruitment 2021
Bihar Board 12th Dummy Admit Card 2022
RBI Assistant Notification 2021
Jee Advanced 2021 Result
NIACL Assistant Recruitment 2021
SBI PO Online Form 2021

Write a class PrintEvenNumbers with a public method printEvenNumbers that takes one parameter arr of type int[]

Write a class PrintEvenNumbers with a public method printEvenNumbers that takes one parameter arr of type int[].

Write code using for-each loop to iterate over the arr if the number is even the program should print is even otherwise, it should print is not even.

Here is an example:

Cmd Args : 13 14 15
13 is not even
14 is even
15 is not even

Hint: You can use value % 2 == 0. Meaning, you can use the modulus operator (%) to divide a number by 2 and get the remainder, to verify if the reminder is equal to 0.

Solution:

package q10878;
public class PrintEvenNumbers {
	
	public void printEvenNumbers(int[] arr) {
		//Write your code here
		
		for (int value=0; value<arr.length; value++) {
			if (arr[value]%2 == 0) {
				System.out.println(arr[value]+" is even");
			} else {
				System.out.println(arr[value]+ " is not even");
			}
		}
	}	
}

Candidates having any kind of query so he/she can ask in our comment section. Our Panel will b reverting back as soon as possible. Thank You. For more details visit our website (https://speedjobalert.com/)

Leave a Comment