Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

c sharp (else if換成switch case)

int a;

Console.WriteLine("輸入數字");

a = Convert.ToInt32(Console.ReadLine());

if (a >= 90)

{

Console.WriteLine("優");

}

else if (a >= 80)

{

Console.WriteLine("甲");

}

else if (a >= 70)

{

Console.WriteLine("乙");

}

else if (a >= 60)

{

Console.WriteLine("丙");

}

else

{

Console.WriteLine("丁");

}

Console.Read();

要怎麼改寫成

switch case的寫法

3 Answers

Rating
  • 1 decade ago
    Favorite Answer

    switch(a)

    {

    case 90:

    console.writeline("甲");

    break;

    case 80:

    console.writeline("乙");

    break;

    case 70:

    console.writeline("丙");

    break;

    case 60:

    console.writeline("丁");

    break;

    }

    因為我是直接用打的!請勿直接複製貼上程式碼

    C#程式碼大小寫是有分的!

    希望可以解決你的問題

    2008-11-19 19:35:19 補充:

    夜深人靜睡眼惺忪沒有看清楚

    a = a / 10;

    switch (a)

    {

    case 9:

    Console.WriteLine("甲");

    break;

    case 8:

    Console.WriteLine("乙");

    break;

    case 7:

    Console.WriteLine("丙");

    break;

    case 6:

    Console.WriteLine("丁");

    break;

    }

    多謝前輩指導了 @@

    Source(s): 自己是寫C#的工程師
  • ㄚ旺
    Lv 5
    1 decade ago

    2 Jason:

    你可以進步的空間還蠻大的.是否再檢查一下程式碼正確性?

  • 1 decade ago

    a/10

    2008-11-19 09:12:38 補充:

    太扯了~我不敢用你~

Still have questions? Get your answers by asking now.