Computer Science, asked by rinkumommu6, 3 months ago

Write a java program to check whether a number is even or odd?

Answers

Answered by ehsan363
3

Explanation:

public class Odd_Even.

int n;

Scanner s = new Scanner(System.

System. out. print("Enter the number you want to check:");

n = s. nextInt();

if(n % 2 == 0)

System. out. println("The given number "+n+" is Even ");

System. out. println("The given number "+n+" is Odd ");

Answered by subhransusahoo94
20

Example 1: Check whether a number is even or odd using if...else statement

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

}

}

Output

Enter a number: 12

12 is even

Similar questions