Create a program in Java that will enter a number and check if the given number is odd or even number.
Sample output:
Enter a number to be check: 18
Number 18 is even number
OR
Enter a number to be check: 18
Then entered number is even number
package oddeven;
import java.util.Scanner;
public class OddEven {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.printf("Enter a number to check: ");
int number = scan.nextInt();
if(number % 2==0){
System.out.printf("\nNumber %d is even number", number);
}
else{
System.out.printf("\nNumber %d is odd number", number);
}
}
}
Comments
Leave a comment