This example will prompt to enter any integer number and as per the formula it will print weather the number is even or odd.
Output:
Please enter any integer number: 7
7 is an odd number
import java.util.Scanner;
public class EvenOdd {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter any integer number: ");
int number = scanner.nextInt();
if (number % 2 == 0)
System.out.println(number + " is an even number");
else
System.out.println(number + " is an odd number");
}
}
Output:
Please enter any integer number: 7
7 is an odd number
No comments:
Post a Comment