Java Program to Check Whether a Number is Even or Odd

by anupmaurya
0 comment 723 views

In order to check the number Whether a Number is Even or Odd, we have divided the number by 2 if it does not leave any remainder, the number is even otherwise number is odd.

Let’s have a look how we can implement this help of a java program.

import java.util.Scanner; public class EvenOdd { public static void main(String[] args) { Scanner reader = new Scanner(; 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"); } }
Code language: Java (java)

What You get as Output , After running the program

Enter a number:25 25 is odd
Code language: CSS (css)

Happy Programming 馃檪

You may also like