Java Program to Check a Number is Even or Odd using if else statement with Explanation

Published: 28 April 2020
on channel: Talented Developer
13,999
143

#java #javatutorialforbeginners #javaprogramming
Java Program to Check a Number is Even or Odd using if ..else statement with Explanation

All Java Programs | Java Coding Interview Questions:
   • All Java Programs | Java Coding Inter...  

Code Repository: https://github.com/talenteddeveloper/...

Follow on Facebook:   / talenteddeveloper  

GitHub:
https://github.com/talenteddeveloper

CodePen:
https://codepen.io/talenteddeveloper/

In this program, you'll learn to check if a number entered by an user is even or odd. This will be done using if...else statement and ternary operator in Java.
In the above program, a Scanner object, scanner is created to read a number from the user's keyboard. The entered number is then stored in a variable num.

Now, to check whether num is even or odd, we calculate its remainder using % operator and check if it is divisible by 2 or not.

For this, we use if...else statement in Java. If num is divisible by 2, we print num is even. Else, we print num is odd.

We can also check if num is even or odd by using ternary operator in Java(   • Java Program to check a number is eve...  )

Other Query :
java odd even number program.
java check odd and even.
java odd or even program.
odd and even numbers.
odd and even program in java.
odd-even java program.
java odd or even.
java program to find odd or even


On this page of the site you can watch the video online Java Program to Check a Number is Even or Odd using if else statement with Explanation with a duration of hours minute second in good quality, which was uploaded by the user Talented Developer 28 April 2020, share the link with friends and acquaintances, this video has already been watched 13,999 times on youtube and it was liked by 143 viewers. Enjoy your viewing!