我正在尝试在静态方法中运行switch函数,并且我一直收到此错误:
File: C:\Users\Darien Springer\Documents\Java\DaysInMonth.java [line: 6]
Error: Cannot switch on a value of type String for source level below 1.7.
Only convertible int values or enum variables are permitted
我查了几个指南,但似乎没有一个指示如何将源级别更改为高于1.7。当我查看设置时,它说DrJava正在运行Java版本1.8,所以我对这个问题感到困惑。这是我的班级文件:
import java.util.Scanner;
public class DaysInMonth {
public static void daysInaMonth (int year_number, String month_name) {
if(year_number % 4 != 0 || month_name != "February") {
switch(month_name) {
case "January":
case "March":
case "May":
case "July":
case "August":
case "October":
case "December":
System.out.print("31");
break;
case "April":
case "June":
case "September":
case "November":
System.out.print("30");
break;
case "February":
System.out.print("28");
break;
default:
System.out.print("Please input ");
break;
}
}
else {
System.out.print("29");
}
}
答案 0 :(得分:1)
您必须从Oracle网页下载并安装新的jdk版本。