使用 if 条件语句判断,自己的学号尾数最后两位能否被2和3整除且不能被4整除,或者能否被5整除且不能被10整除,以上两个条件满足其一,则显示 y 否则显示 n 。
public static void fun(String num) {
// 学号尾数最后两位
int lastTwoNumber = Integer.parseInt(num.substring(num.length() - 2));
System.out.println(lastTwoNumber);
if ((lastTwoNumber % 2 == 0 && lastTwoNumber % 3 == 0 && lastTwoNumber % 4 != 0)
|| (lastTwoNumber % 5 == 0 && lastTwoNumber % 10 != 0)) {
System.out.println("y");
} else {
System.out.println("n");
}
}