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 PrintOddNumbers with a public method printOddNumbers that takes one parameter arr of type int[].

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

Use for-each loop to iterate over the arr and the program should print is odd if the element is odd otherwise, it should print is not odd.

For example:

Cmd Args : 1 2 3 4 5 6
1 is odd
2 is not odd
3 is odd
4 is not odd
5 is odd
6 is not odd

Solution:

package q10879;

public class PrintOddNumbers{
	public static void printOddNumbers(int[] arr) {
		
		for (int value=0; value<=arr.length; value++) {
			if (arr[value]%2 == 0) {
				System.out.println(arr[value]+" is not odd");
			} else {
				System.out.println(arr[value]+" is odd");
			}
		}
	}
}

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