Java Program To Check Odd Or Even
Chapter:
Miscellaneous
Last Updated:
18-06-2016 16:43:46 UTC
Program:
/* ............... START ............... */
import java.util.Scanner;
public class JavaOddEven {
private static Scanner scanner;
public static void main(String args[]) {
int x;
System.out.println("Please enter a number to check whether it is odd or not ");
scanner = new Scanner(System.in);
x = scanner.nextInt();
if (x % 2 == 0)
System.out.println("You entered an even number.");
else
System.out.println("You entered an odd number.");
}
}
/* ............... END ............... */
Output
Output Please enter a number to check whether it is odd or not
3 You entered an odd number. 4 You entered an even number.
Notes:
-
If the number is divisible by 2 then it will be even, otherwise it is odd.
Tags
Odd Or Even Check, Java