if(choice == 1) price = 3.0;
else if(choice == 2) price = 2.5;
else if(choice == 3) price = 4.0;
else if(choice == 4) price = 3.5;
else{ price = 0.0; }
switch
{
case 1: price=3.0; break;
case 2: price=2.5; break;
case 3:price=4.0;break;
case 4: price=3.5;break;
price=0.0; break;
}
choice default
举一反三
- 设变量已正确定义,选项()与以下程序段不等价。switch(choice){case1:price=3.0;case2:price=2.5;default:price=0.0;}A.price=0.0;B.switch(choice){default:price=0.0;case2:price=2.5;case1:price=3.0;}C.price=0.0;switch(choice){case1:price=3.0;case2:price=2.5;}D.if(choice==1){price=3.0;price=2.5;price=0.0;}elseif(choice==2){price=2.5;price=0.0;}else{price=0.0;}
- 以下代码的输出结果是()。publicclassTest{publicstaticvoidmain(String[]args){double[]price=newdouble[5];price[0]=98.10;price[1]=32.18;price[2]=77.75;System.out.print((int)price[0]+""+(int)price[1]+""+(int)price[2]+""+(int)price[3]+""+(int)price[4]);}}
- 以下选项中与if(a==1) a=b;else a++;语句功能不同的switch语句是( )。(a == 1 中的符号是恒等于) A: switch(a==1) {case 0: a=b;break; case 1:a++;} B: switch(a) {case 1: a=b;break; default:a++;} C: switch(a) {default:a++;break; case 1: a=b;} D: switch(a==1) {case 1: a=b;break; case 0:a++;}
- 中国大学MOOC: When the price of a good increases, all else equal, the higher price
- 与分支语句有关的关键词有if、else、switch、case和break
内容
- 0
对以下的switch语句说法正确的是 switch(num){case 1: ...break; case 0: ...break;case 2: ...break; default: ...break; }
- 1
The switch statement with different functions from the statement if (a == 1) a = b; else a ++; is ( ). A: switch(a) { case 1:a=b;break; <br/>default : a++; <br/>} B: switch(a==1) { case 0:a=b;break;<br/>case 1: a++;<br/>} C: switch(a) { default:a++;break; <br/>case 1:a=b; <br/>} D: switch(a) { default:a++;break; <br/>case 1:a=b; <br/>}
- 2
若a、b、c1、c2、x、y均是整型变量,正确的switch语句是______。①switch(a+b);{ case 1:y=a+b;break;case 0:y=a-b;break;}②switch(a*a+b*b){ case 3:case 1:y=a+b;break;case 3:y=b-a;break;}③switch { case c1:y=a-b;break;case c2:x=a*b;break;default:x=a+b;}④switch (a-b){ default:y=a*b;break;case 3:case 4:x=a+b;break;case 10:case 11:y=a-b;break;} A: ① B: ② C: ③ D: ④
- 3
中国大学MOOC: 与分支语句有关的关键词有if、else、switch、case和break
- 4
若a、b、c1、c2、x、y均是整型变量,以下正确的switch语句是 A: swich(a+b);{ case 1 : y=a+b; break;case 0 : y=a-b; break; } B: switch(a*a+b*b){ case 3 :case 1 : y=a+b; break;case 3 : y=b-a, break; } C: switch a{ case c1 : y=a-b; break;case c2 : x=a*d; break;default : x=a+b; } D: switch(a-b){ default : y=a*b; break;case 3 : case 4 : x=a+b;break;case 10 : case 11: y=a-b: break; }