Skip to content

Instantly share code, notes, and snippets.

@jonathan-irvin
Last active October 5, 2015 18:19
Show Gist options
  • Save jonathan-irvin/1412cdad3ea1920b81fa to your computer and use it in GitHub Desktop.
Save jonathan-irvin/1412cdad3ea1920b81fa to your computer and use it in GitHub Desktop.
Divisible by 5 or 6
import java.util.Scanner;
public class Divby5or6 {
public static void main(String[] args) {
System.out.print("Enter A Number: ");
Scanner input = new Scanner(System.in);
int number = input.nextInt();
boolean divisibleBy5 = (number % 5 == 0);
boolean divisibleBy6 = (number % 6 == 0);
if((divisibleBy5 && !(divisibleBy6)){
System.out.print(number + " is divisible by 5, but not 6");
}else if((divisibleBy6) && !(divisibleBy5)){
System.out.print(number + " is divisible by 6, but not 5");
}else if (divisibleBy5 && divisibleBy6){
System.out.print(number + " is divisible by 5 and 6.");
}else if (!(divisibleBy5) && !(divisibleBy6)) {
System.out.print(number + " is not divisible by 5 or 6.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment