在编写 "从键盘上输入某一年月,判断这年的这个月份有多少天。" 时运行时提示:(意外的类型) (需要 变量) (找到 值)
package Exam;
import java.time.Month;
import java.time.Year;
import java.util.Scanner;
public class Exam1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入某一年");
int Year = sc.nextInt();
System.out.println("请输入某一月");
int Month = sc.nextInt();
if (Year / 4 = 0 & Year / 400 = 0 & Month = 1 / 3 / 5 / 7 / 8 / 10 / 12) {
System.out.println("这年这个月有31天");
} else if (Year / 4 != 0 & Year / 400 != 0 & Month = 4 / 6 / 11) {
System.out.println("这年这个月有30天");
} else if (Year / 4 == 0 & Year / 400 == 0 & Month = 2) {
System.out.println("这年这个月有29天");
} else if (Year / 4 != 0 & Year / 400 != 0 & Month = 2) {
System.out.println("这年这个月有28天");
} else {
System.out.println("请输入正确的年月份");
}
}
}
无法运行,报错 (意外的类型) (需要 变量) (找到 值)
想要正常运行应该怎么改??
(新手入门)
判断等于两个==,两个条件同时满足用两个&&,比如下边这个判断
else if (Year / 4 == 0 & &Year / 400 == 0 & &Month = =2
判断是用==。
一个等于号是赋值不是判断。
判断用==
判断用== ,两个条件同时满足用&&,
多个月份同时判断也不正确,你那样写相当于1除以3取整然后在除以5取整了,判断月份的方式也不正确,
写的也麻烦了,除了二月以外,其余的月份有几天不需要判断是不是闰年。