Even or odd program in java

The number which is divisible by 2 is known as even number and the number which is not divisible by 2 is odd number.

in programming we use % operator to check divisibility.

The % operator returns the remainder of division. If a number is completely divisible its remainder is 0.

So any number is completely divisible by 2 then its remainder is zero.

4%2,20%2,60%2 all return zero.

5%2,45%2,51%2 its remainder is non zero.

Even or odd number program in java using if else

Scanner class is used to take input from standard input stream that is keyboard.

Then perform modulo operation with 2 if remainder is 0 than a even number else number is odd.

Output

Even or odd number program in java using switch case

switch(number%2) returns 0 or non zero value. So there should be two case statement case 0 for even numbers and default for non zero numbers.

Output

Even or odd number program in java using ternary operator

Output