write a program to take a number as input from the user and check of it is even number or odd number in Java
Answers
Answered by
1
Answer:
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
Explanation:
Similar questions