Even or Odd Program in Java Using If Else

Mod in Java for beginners, odd or even in the java programming language. This is a simple collection of Java programs for beginners to check the number

Odd or Even Number in Java

A number that can be split into two equal groups is called an even number. A number that cannot be split into two equal groups is called an odd number. Even numbers, regardless matter how many digits they have, finish in 2, 4, 6, 8, or 0 .

Mod and How to Declare in Java

The remainder or Modulo After division, the operator returns the remainder of the two integers. If you’re given two integers, say A and B, where A is the dividend and B is the divisor, is there a residue of A and B’s division? The modulo operator is a percentage-based arithmetic operator.

Expr left percent expr right evaluates to the integer remainder if both operands for percent and the modulus operator are of type int. Because 8 divided by 3 leaves a residual of 2, 8 percent 3 evaluates to 2. The modulus operator (with both operands) evaluates to int when both operands are of type int.

If Else Condition in Java

If a stated condition is true, the if/else statement executes a block of code. Another piece of code can be run if the condition is false. The if/else statement is part of JavaScript’s “Conditional” Statements, which are used to execute various actions depending on certain situations.

Odd or Even Program for Mod in Java

After division, the Modulo or Remainder Operator returns the remainder of the two numbers. If you’re given two numbers, say A and B, where A is the dividend and B is the divisor, is there a residue of A and B’s division.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = reader.nextInt();
if(num % 2 == 0)
System.out.println(num + " is even");
else
System.out.println(num + " is odd");
}
}

Output
2020 is even