用IF/THEN/ELSEIF/ELSE代替这种基本结构
int month = 8;
String monthString;
if (month == 1) {
monthString = "January";
} else if (month == 2) {
monthString = "February";
}
... // and so on
Run Code Online (Sandbox Code Playgroud)
拥有它会很高兴
int month = 8;
String monthString;
switch (month) {
case 1: monthString = "January";
break;
case 2: monthString = "February";
break;
..... // and so on
case 12: monthString = "December";
break;
default: monthString = "Invalid month";
break;
}
Run Code Online (Sandbox Code Playgroud)
这样可以提高可读性,并且由于意图清晰而使调试更容易.
Dav*_*sby 13
2018年 - 是的!!!! - 如果最后是 - 好消息 - 立即切换支持在黄金时刻 跳转到YouTube会话的视频中的确切时间
2014年 - 不是在这个可悲的时刻.自2009年以来,我一直在等待此功能,这是一个高度要求的通过以下社区的链接.
小智 9
monthMap = new Map<Integer,String>();
monthMap.put(1,'JAN');
monthMap.put(2,'FEB');
monthMap.put(3,'MAR');
monthMap.put(4,'APR');
monthMap.put(5,'MAY');
monthMap.put(6,'JUN');
monthMap.put(7,'JUL');
monthMap.put(8,'AUG');
monthMap.put(9,'SEP');
monthMap.put(10,'OCT');
monthMap.put(11,'NOV');
monthMap.put(12,'DEC');
Run Code Online (Sandbox Code Playgroud)
然后根据您的整数月值进行获取.
没有必要写一个大的if-else.
| 归档时间: |
|
| 查看次数: |
26377 次 |
| 最近记录: |