📄 5-1.txt
字号:
一个程序用于计算一年中已度过的天数,month表示月份,day表示日期,计算结果保存在total中。(为了简便,我们把闰年的情况排除在外。
C、C++程序:
total=365;
switch(month){
case 1:total -= 31;
case 2:total -= 28;
case 3:total -= 31;
case 4:total -= 30;
case 5:total -= 31;
case 6:total -= 30;
case 7:total -= 31;
case 8:total -= 31;
case 9:total -= 30;
case 10:total -= 31;
case 11:total -= 30;
case 12:total -= 31;
default:total += day;
}
这种写法在C#中是不允许的。
C#语言:
total=365;
switch(month){
case 1:total -= 31; goto case 2;
case 2:total -= 28; goto case 3;
case 3:total -= 31; goto case 4;
case 4:total -= 30; goto case 5;
case 5:total -= 31; goto case 6;
case 6:total -= 30; goto case 7;
case 7:total -= 31; goto case 8;
case 8:total -= 31; goto case 9;
case 9:total -= 30; goto case 10;
case 10:total -= 31; goto case 11;
case 11:total -= 30; goto case 12;
case 12:total -= 31; goto default;
default:total += day;
}
下面的程序是正确的。
switch(i){
case 0:
while(true) F();
case 1:
throw new ArgumentException();
case 2:
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -