Home Tutorial Java Core Check whether highest number is even or odd

 
 

Check whether highest number is even or odd
Posted on: July 6, 2010 at 12:00 AM
Advertisement
In this section, you will learn how to check highest number between the two numbers and then determine whether it is odd or even.

Check whether highest number is even or odd

In this section, you will learn how to check highest number between the two numbers and then determine whether it is odd or even. For this, we have taken two integer variables num1 and num2 and initialized to 40 and 37 respectively.Using the operators, we have determined the highest number.After getting the highest number, we have created a condition that if the highest number is totally divided by 2,then it is even, otherwise, it is odd.

Here is the code:

class CheckHighestNumber {
	public static void main(String[] args) {
		int num1 = 40;
		int num2 = 37;
		int highestNumber = 0;
		if (num1 > num2) {
			highestNumber = num1;
		} else {
			highestNumber = num2;
		}
		if (highestNumber % 2 == 0) {
			System.out.println("Highest Number " + highestNumber + " is Even");
		} else {
			System.out.println("Highest Number " + highestNumber + " is Odd");
		}
	}
}

Output:

Highest Number 40 is Even
Advertisement

Related Tags for Check whether highest number is even or odd:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 6, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com