• 2021-04-14
    请写出与以下else-if语句等价的switch语句。
    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

    内容

    • 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;   }