Even or Odd in Java
Q. Write a Java program to check even or odd number
import java.util.Scanner;
public class EvenOddCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Ask the user to enter a number
System.out.print("Enter an integer number: ");
int number = scanner.nextInt();
// Check if the number is even or odd
if (number % 2 == 0) {
System.out.println(number + " is an even number.");
} else {
System.out.println(number + " is an odd number.");
}
scanner.close();
}
}
Q. Write an algorithm to check even or odd number
1. Start
2. Read an integer value and store it in a variable number
3. Check if number % 2 == 0
- If true, print "number is even"
- Else, print "number is odd"
4. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com