java编程出现错误,是33:错误:解析时已到达文件结尾 \\求大神修改。
春,夏,秋,冬
}
public class EnumDemo{
Season season;
public EnumDemo(Season season) {
this. season=season;
}
public void saySeason () {
switch (season) {
case 春:System.out.println("现在是春季.");
break;
case 夏:System.out.println("现在是夏季.");
break;
case 秋:System.out.println("现在是秋季.");
break;
default:System.out.println("现在是冬季。");
break;
}
}
//运行测试
public class Test{
public static void main(String[] args) {
EnumDemo spring=new EnumDemo (Season.春);
spring. saySeason ();
EnumDemo summer=new EnumDemo (Season.夏);
summer. saySeason ();
EnumDemo fall=new EnumDemo (Season.秋);
fall. saySeason ();
EnumDemo winter=new EnumDemo (Season.冬);
winter. saySeason ();
}
} 展开
经过测试, 无问题,
import aa.aa;
import aa.aa.Season;
public class test {
public static void main(String[] args) {
aa spring=new aa(Season.春);
spring.saySeason();
aa summer=new aa(Season.夏);
summer.saySeason();
aa fall=new aa(Season.秋);
fall.saySeason();
aa winter=new aa(Season.冬);
winter.saySeason();
}
}
package aa;
public class aa {
public enum Season{
春,夏,秋,冬
}
Season season;
public aa(Season season) {
this. season=season;
}
public void saySeason () {
switch (season) {
case 春:System.out.println("现在是春季.");
break;
case 夏:System.out.println("现在是夏季.");
break;
case 秋:System.out.println("现在是秋季.");
break;
default:System.out.println("现在是冬季。");
break;
}
}
//运行测试
}
enum Season {
春, 夏, 秋, 冬
}
public class EnumDemo {
Season season;
public EnumDemo(Season season) {
this.season = season;
}
public void saySeason() {
switch (season) {
case 春:
System.out.println("现在是春季.");
break;
case 夏:
System.out.println("现在是夏季.");
break;
case 秋:
System.out.println("现在是秋季.");
break;
default:
System.out.println("现在是冬季。");
break;
}
}
//运行测试
public static void main(String[] args) {
EnumDemo spring = new EnumDemo(Season.春);
spring.saySeason();
EnumDemo summer = new EnumDemo(Season.夏);
summer.saySeason();
EnumDemo fall = new EnumDemo(Season.秋);
fall.saySeason();
EnumDemo winter = new EnumDemo(Season.冬);
winter.saySeason();
}
}
大神还有一个错误:5:错误:类EnumDemo是公共的,应在名为EnumDemo.java的文件中声明
public class EnumDemo < (class的c下有一个小箭头)
那是因为public 的EnumDemo必须写在同名的java文件里,你把你的测试文件改名为EnumDemo.java就可以了