This program has been simplified for beginners to find the given number is Odd or Even.
import java.util.Scanner;
public class OddrEven {
public static void main(String args[]){
//To get the input number from user
System.out.println("Enter the number: ");
Scanner sc = new Scanner(System.in);
int inp = sc.nextInt();
sc.close();
//Simple logic to check the number is Odd or Even
int temp = inp % 2;
if (temp == 0){
System.out.println("This is a even number.");
}else{
System.out.println("This is a odd number.");
}
}
}
Output:
Enter the number:
45
This is a odd number.
Enter the number:
22
This is a even number.
No comments:
Post a Comment