首页 > 学院 > 开发设计 > 正文

Enumeration基础

2019-11-08 20:02:10
字体:
来源:转载
供稿:网友
//Enumberation Fundamentals// method/* *public static enum-type [] values();//returns an array *public static enum-type valueof(String str);//returns enumeration constant */enum Apple { Jonathan, GoldenDel, RedDel, Winesap, Cortland}class EnumDemo { public static void main(String args []) { Apple ap; ap= Apple.RedDel; System.out.PRintln("Value of ap: "+ ap); System.out.println(); ap= Apple.GoldenDel; if(ap == Apple.GoldenDel) System.out.println("ap contains GoldenDel./n"); // switch(ap) { case Jonathan: System.out.println("Jonathan is red."); break; case GoldenDel: System.out.println("Golden Delicious is yellow."); break; case RedDel: System.out.println("reddel is red."); case Winesap: System.out.println("Winesap is red."); case Cortland: System.out.println("Cortland is red."); } Apple allapples[]= Apple.values(); for(Apple a: allapples) System.out.println(a); System.out.println(); ap= Apple.valueOf("Winesap"); System.out.println("ap contains "+ ap); }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表