/*P2Q3
*Name:Wang Chaoran
*Description:(Using the &&, || and ^ operators)
Write a program that prompts the user to enter an integer
and determines whether it is divisible by 5 and 6, whether
it is divisible by 5 or 6, and whether it is divisible by 5 or 6,
but not both. For example, if your input is 10, the output should be
Is 10 divisible by 5 and 6? false
Is 10 divisible by 5 or 6? true
Is 10 divisible by 5 or 6, but not both? true
*/
import java.util.Scanner;
class P2Q3
{
public static void main(String[] args)
{
//Step One:Create a scanner
Scanner scan = new Scanner(System.in);
//Step Two:Read in an integer
System.out.println("Please input an integer: ");
int integer = scan.nextInt();
//Compute and display result
if((integer % 5 == 0)&&(integer % 6 ==0))
{
System.out.println("Is "+integer+" divisible by 5 and 6? true");
System.out.println("Is "+integer+" divisible by 5 or 6, but not both? false");
System.out.println("Is "+integer+" divisible by 5 or 6? true");
}
else if((integer % 5 == 0)^(integer % 6 ==0))
{
System.out.println("Is "+integer+" divisible by 5 and 6? false");
System.out.println("Is "+integer+" divisible by 5 or 6, but not both? true");
System.out.println("Is "+integer+" divisible by 5 or 6? true");
}
else
{
System.out.println("Is "+integer+" divisible by 5 and 6? false");
System.out.println("Is "+integer+" divisible by 5 or 6, but not both? false");
System.out.println("Is "+integer+" divisible by 5 or 6? false");
}
}
}