Coding Practice

Write a Java program to check whether a number is divisible by 5 and 11 or not

Check whether a number is divisible by 5 and 11 or not
Sample Output
Check whether a number is divisible by 5 and 11 or not.

Enter a number: 20
20 is divisible by 5.
Java-Source Code
//package ifelsejava;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int number;
Scanner input = new Scanner(System.in);
System.out.println("Check whether a number is divisible by 5 and 11 or not.\n");
System.out.print("Enter a number: ");
number = input.nextInt();
if (number % 5 == 0) {
System.out.println(number + " is divisible by 5.");
} else if (number % 11 == 0) {
System.out.println(number + " is divisible by 11.\n");
} else {
System.out.println(number + " is not divisible by 5 and 11.\n");
}
}
}
Sample Output
Check whether a number is divisible by 5 and 11 or not.

Enter a number: 99
99 is divisible by 11.

No comments:

Post a Comment

Change Theme
X