This Java program prompts the user to input a number and then determines whether the number is even or odd using the modulo operator and conditional statements.
The Scanner class is used to read input from the user, and the program prompts the user to enter a number and stores it in the variable num.
The program then uses an if-else statement with the modulo operator to check whether num is even or odd. If num is divisible by 2 (i.e., the remainder is 0), it prints the message "Even Number". If num is not divisible by 2 (i.e., the remainder is 1), it prints the message "Odd Number".
import java.util.Scanner; class EvenOdd { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the Number : "); int num = input.nextInt(); if(num%2==0) System.out.println("Even Number"); else System.out.println("Odd Number"); } }
Enter the Number : 51 Odd Number
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions