Share on Google+Share on Google+

Check whether highest number is even or odd

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

Advertisements

Advertisement

Posted on: July 6, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.