-->
当前位置:首页 > 题库 > 正文内容

程序填空题:写出与switch语句等价的else-if语句[4]

Luz4年前 (2021-05-10)题库6889
写出与以下switch语句等价的else-if语句。
```c++
switch (ch){
case '0' : case '1' : case '2' : case '3' : case '4' :
case '-':
minus++; break;
case '5' : case '6' : case '7' : case '8' : case '9' :
digit ++;break;
default:
other ++; break;
}
```

```c++
if@@[(ch == '-' || (ch >= '0' && ch <= '4') )](1) {
minus++;
}else if@@[(ch >= '5' && ch <= '9')](1) {
digit ++;
}else {
@@[other ++;](1)
}
```








答案:
第1空:(ch == '-' || (ch >= '0' && ch <= '4') )

第2空:(ch >= '5' && ch <= '9')

第3空:other ++;

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。