java 枚举和foreach的问题
enumApple{Jonathan(10),Godendel(9),Reddel(12);privateintprice;Apple(intp){price=p;}in...
enum Apple {
Jonathan(10), Godendel(9), Reddel(12);
private int price;
Apple(int p) {
price = p;
}
int getPrice() {
return price;
}
}
public class EnumDemo2 {
public static void main(String[] args) {
Apple ap;
System.out.println("Godendel costs " + Apple.Godendel.getPrice() + "cents");
System.out.println("All apple prices");
for (Apple a : Apple.values()) {
System.out.println(a + "costs" + a.getPrice() + "cents");
}
}
}
倒数第二行的foreach里Apple.values()的返回值是什么,foreach里for(int e;a)a一般是什么 展开
Jonathan(10), Godendel(9), Reddel(12);
private int price;
Apple(int p) {
price = p;
}
int getPrice() {
return price;
}
}
public class EnumDemo2 {
public static void main(String[] args) {
Apple ap;
System.out.println("Godendel costs " + Apple.Godendel.getPrice() + "cents");
System.out.println("All apple prices");
for (Apple a : Apple.values()) {
System.out.println(a + "costs" + a.getPrice() + "cents");
}
}
}
倒数第二行的foreach里Apple.values()的返回值是什么,foreach里for(int e;a)a一般是什么 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询