Question: Write a program to check whether the given number is even or odd in JAVA
Answer:
An even number is any number whose remainder of the division over 2 is equal to 0. It is also said that they are multiples of 2.
An odd number is any number whose remainder of the division out of 2 is equal to 1.
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import java.util.Scanner; public class JavaExamples { public static void main(String[] args) { int x; System.out.println("Enter an integer to check if it is odd or even"); Scanner in = new Scanner(System.in); x = in.nextInt(); if (x % 2 == 0) System.out.println("The number is even."); else System.out.println("The number is odd."); } } |