Odd or even program in java using a mod operator

Write a program to print Odd or Even in java using mod operator. For beginners, odd or even in the java programming language. This is a simple collection of Java programs for beginners to check the number

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 

What is odd and 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 .

What is mod and how to declare mod 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 program 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 in java using a mod operator

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.