Java program that prompts the user to enter an integer and checks whether the number is divisible by both 5 and 6, or neither of them, or just one of them.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> */<br /><br />import java.util.Scanner;<br /><br />public class Ex03_12 {<br /> public static void main(String[] args) {<br /> int num;<br /> Scanner input = new Scanner(System.in);<br /> System.out.print("Enter an integer: ");<br /> num = input.nextInt();<br /> if (num % 5 == 0 && num % 6 == 0) {<br /> System.out.println(num + " is divisible by both 5 and 6");<br /> } else if (num % 5 == 0 || num % 6 == 0) {<br /> System.out.println(num + " is divisible by 5 or 6, but not both");<br /> } else {<br /> System.out.println(num + " is not divisible by either 5 or 6");<br /> }<br /> }<br />}<br /> |
Sample program run |
Click here to see other solutions to Introduction to Java Programming.