Advertisement
newbninja

Odd or Even

Oct 16th, 2023
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OddEvenChecker {
  4.     public static void main(String[] args) {
  5.         // Create a Scanner object to read input from the user
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         // Prompt the user to enter a number
  9.         System.out.print("Enter a number: ");
  10.  
  11.         // Read the number from the user
  12.         int number = scanner.nextInt();
  13.  
  14.         // Close the Scanner
  15.         scanner.close();
  16.  
  17.         // Check if the number is odd or even
  18.         if (number % 2 == 0) {
  19.             System.out.println(number + " is even.");
  20.         } else {
  21.             System.out.println(number + " is odd.");
  22.         }
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement