/**
* 使用運算符&&、||和^
* 提示用戶輸入一個整數:
* 判斷它是否能被5和6整除,是否能被5或6整除,以及是否能被5或6整除但不能被它們整除。
*/
package Test;
import java.util.Scanner;
public class T326Scanner {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = input.nextInt();
boolean even = ((num % 5 == 0 && num % 6 == 0) ^ (num % 5 == 0 || num % 6 == 0));
System.out.println((even == false)
? "Is " + num + " divisible by 5 and 6? " + even
: "\nIs " + num + " divisible by 5 or 6? " + even
+ "\nIs " + num + " divisible by 5 or 6, but not both? " + even);
}
}
第3章:使用運算符&&、||和^
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.