A number is said to be evenly divisible by 9 if it is divisible by 9 and at the same time it is even. For example 18 is evenly divisible by 9 but 27 is not. A program is required that accepts an integer and checks whether it is evenly divisible by 9 or not and then prints an appropriate message.
import java.util.*;
class App {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter number:");
int number = keyboard.nextInt();
if (number % 9 == 0 && number % 2 == 0) {
System.out.println(number + " is evenly divisible by 9");
} else {
System.out.println(number + " is NOT evenly divisible by 9");
}
keyboard.close();
}
}
Comments
Leave a comment