用java实现一个枚举类,有两个成员属性,是编号和各省份的地级市
时间: 2023-05-29 07:02:32 浏览: 103
public enum City {
BEIJING(1, "北京"),
TIANJIN(2, "天津"),
SHANGHAI(3, "上海"),
CHONGQING(4, "重庆"),
HEBEI(5, "河北"),
SHANXI(6, "山西"),
LIAONING(7, "辽宁"),
JILIN(8, "吉林"),
HEILONGJIANG(9, "黑龙江"),
JIANGSU(10, "江苏"),
ZHEJIANG(11, "浙江"),
ANHUI(12, "安徽"),
FUJIAN(13, "福建"),
JIANGXI(14, "江西"),
SHANDONG(15, "山东"),
HENAN(16, "河南"),
HUBEI(17, "湖北"),
HUNAN(18, "湖南"),
GUANGDONG(19, "广东"),
GUANGXI(20, "广西"),
HAINAN(21, "海南"),
SICHUAN(22, "四川"),
GUIZHOU(23, "贵州"),
YUNNAN(24, "云南"),
SHAANXI(25, "陕西"),
GANSU(26, "甘肃"),
QINGHAI(27, "青海"),
TIBET(28, "西藏"),
NINGXIA(29, "宁夏"),
XINJIANG(30, "新疆");
private int code;
private String name;
City(int code, String name) {
this.code = code;
this.name = name;
}
public int getCode() {
return code;
}
public String getName() {
return name;
}
}
阅读全文