Share your repls and programming experiences

← Back to all posts
Odd or even program in java using a mod operator
RaghunathThilag (1)

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 programmes 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

Link: https://inlarn.com/odd-or-even-program-in-java-using-a-mod-operator/