標題:
switch 判斷式
[打印本頁]
作者:
tonyh
時間:
2014-5-17 15:01
標題:
switch 判斷式
本帖最後由 tonyh 於 2014-5-17 15:14 編輯
將成績分級程式, 以 switch 語法改寫.
90分~100分 優
80分~89分 甲
70分~79分 乙
60分~69分 丙
0分~59分 丁
import java.io.Console;
public class ch13
{
public static void main(String args[])
{
Console c=System.console();
int score,level;
System.out.print("請輸入你的成績: ");
score=Integer.parseInt(c.readLine());
level=score/10;
switch(level)
{
case 10:
case 9:
System.out.println("優");
break;
case 8:
System.out.println("甲");
break;
case 7:
System.out.println("乙");
break;
case 6:
System.out.println("丙");
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
System.out.println("丁");
break;
default:
System.out.println("輸入錯誤!");
}
}
}
複製代碼
作者:
張瀚仁
時間:
2014-5-17 15:22
import java.io.Console;
public class ch13
{
public static void main(String args[])
{
Console c=System.console();
int x,y;
System.out.print("請輸入成績: ");
x=Integer.parseInt(c.readLine());
System.out.println("您剛輸入的成績為"+x);
y=x/10;
switch(y)
{
case 10:
case 9:
System.out.println("優");
break;
case 8:
System.out.println("甲");
break;
case 7:
System.out.println("乙");
break;
case 6:
System.out.println("丙");
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
System.out.println("丁");
break;
default:
System.out.println("輸入錯誤");
}
}
}
複製代碼
作者:
劉泳鱔
時間:
2014-5-17 15:22
import java.io.Console;
public class ch12
{
public static void main(String args[])
{
Console c=System.console();
String str;
int x,y;
System.out.print("請輸入你的成績: ");
x=Integer.parseInt(c.readLine());
x=y/10;
switch(y)
{
case 10:
case 9:
System.out.print("優")
break;
case 8:
System.out.print("甲")
break;
case 7:
System.out.print("乙")
break;
case 6:
System.out.print("丙")
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
System.out.print("丁")
break;
default:
System.out.print
}
}
複製代碼
作者:
許逸群
時間:
2014-5-17 15:25
import java.io.Console;
public class ch13
{
public static void main(String args[])
{
Console c=System.console();
int score,level;
System.out.print("請輸入你的成績: ");
score=Integer.parseInt(c.readLine());
level=score/10;
switch(level)
{
case 10:
case 9:
System.out.println("優");
break;
case 8:
System.out.println("甲");
break;
case 7:
System.out.println("乙");
break;
case 6:
System.out.println("丙");
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
System.out.println("丁");
break;
default:
System.out.println("輸入錯誤!");
}
}
複製代碼
作者:
鎧言
時間:
2014-5-17 15:26
import java.io.Console;
public class ch13
{
public static void main(String args[])
{
Console c=System.console();
int score,level;
System.out.print("請輸入你的成績: ");
score=Integer.parseInt(c.readLine());
level=score/10;
switch(level)
{
case 10:
case 9:
System.out.println("優");
break;
case 8:
System.out.println("甲");
break;
case 7:
System.out.println("乙");
break;
case 6:
System.out.println("丙");
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
System.out.println("丁");
break;
default:
System.out.println("輸入錯誤!");
}
}
}
複製代碼
作者:
林以諾
時間:
2014-5-17 15:28
import java.io.Console;
public class ch13
{
public static void main(String args[])
{
Console c=System.console();
String str;
int x,y;
System.out.print("請輸入你的分數: ");
x=Integer.parseInt(c.readLine());
y=x/10;
switch(y)
{
case 10:
case 9:
str="優";
break;
case 8:
str="甲";
break;
case 7:
str="乙";
break;
case 6:
str="丙";
break;
case 5:
case 4:
case 3:
case 2:
case 1:
str="丁";
break;
default:
str="輸入錯誤";
}
System.out.print(str);
}
}
複製代碼
作者:
黃崇維
時間:
2014-5-17 15:29
import java.io.Console;
public class ch13
{
public static void main(String args[])
{
Console c=System.console();
int score,level;
System.out.print("請輸入你的成績: ");
score=Integer.parseInt(c.readLine());
level=score/10;
switch(level)
{
case 10:
case 9:
System.out.println("優");
break;
case 8:
System.out.println("甲");
break;
case 7:
System.out.println("乙");
break;
case 6:
System.out.println("丙");
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
System.out.println("丁");
break;
default:
System.out.println("輸入錯誤!");
}
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2