Write a Java Program to Check Whether a Number is Even or Odd

Write a Java Program to Check Whether a Number is Even or Odd

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import java.util.Scanner;

public class EvenOdd {

    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");
    }
}

 

 

Final output

1 thought on “Write a Java Program to Check Whether a Number is Even or Odd”

Leave a Comment