HelpWithAssignment Blog

Java Program an example on finding whether a Number is Even or an Odd number

Java is one of the most popular Programming languages in use today in Application software and Web Applications. It is a general-purpose, concurrent, class based and object oriented language that is specifically designed to have implementation dependencies as possible.

Let us look at an example on finding whether a Number is Even or an Odd number.

public class FindEvenOrOddNumber {

public static void main(String[] args) {

//create an array of 10 numbers
int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10};

for(int i=0; i < numbers.length; i++){
/*
* use modulus operator to check if the number is even or odd.
* If we divide any number by 2 and reminder is 0 then the number is
* even, otherwise it is odd.
*/
if(numbers[i]%2 == 0)
System.out.println(numbers[i] + ” is even number.”);
else
System.out.println(numbers[i] + ” is odd number.”);

}
}
}

Here in this example an array is being created and defined. Here “for(int i=0; i < numbers.length; i++){ “ is meant to be the initialization and definition. For(int i=0; I < numbers.length; i++ means that the I cannot be zero and must be greater than the divisor in this case because as we move forward in the code we can see that the definition for the array says that if the number is divided by 2 and the remainder is 0 then the number is an even number. But, mathematically 0 is neither an odd nor an even number, so clearly this rule cannot be broken.

The array “create an array of 10 numbers” is being initiated with a loop “for(int i=0; i < numbers.length; i++){ /*” to calculations to be performed which completes the whole array and the outputs of whether the numbers are even or odd are returned.

At HelpWithAssignment.com we provide the best Java Assignment and Homework help. We also offer Online Tutoring in Java. For more help on Java Programming help you can visit our website at http://www.helpwithassignment.com/programing-assignment-help .

This article is in continuation with our previous article on Java Assignment Help

Leave a comment