標題:
switch 判斷式
[打印本頁]
作者:
tonyh
時間:
2014-11-1 17:17
標題:
switch 判斷式
本帖最後由 tonyh 於 2014-11-1 17:42 編輯
將成績分級程式, 以 switch 語法改寫.
90分~100分 優
80分~89分 甲
70分~79分 乙
60分~69分 丙
0分~59分 丁
import java.io.Console;
public class ch12
{
public static void main(String[] args)
{
int score, level;
Console c=System.console();
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-11-1 17:41
本帖最後由 張郁庭 於 2014-11-1 17:58 編輯
import java.io.Console;
public class ch012
{
public static void main(String args[])
{
int score, level;
Console c=System.console();
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-11-1 17:42
import java.io.Console;
public class ch10
{
public static void main(String args[])
{
float x,y;
Console c=System.console();
System.out.print("請輸入分數: (0~100分)");
x=Float.parseFloat(c.readLine());
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:
System.out.println("丁");
break;
case 4:
case 3:
case 2:
case 1:
case 0:
default;
System.out.println("靠");
}
}
複製代碼
作者:
劉得恩
時間:
2014-11-1 17:42
import java.io.Console;
public class ch11
{
public static void main(String[] args)
{
int score,level;
Console c=System.console();
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:
run();
}
}
static void run()
{
System.out.println("輸入錯誤!");
while(true)
System.out.println("去吃屎!!!!!!!");
}
}
複製代碼
作者:
張峻瑋
時間:
2014-11-1 17:45
import java.io.Console;
public class c6
{
public static void main(String args[])
{
int a,b;
Console c=System.console();
System.out.print("請輸入成績: ");
a=Integer.parseInt(c.readLine());
b=a/10;
switch(b)
{
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-11-1 17:45
import java.io.Console;
public class ch12
{
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:
System.out.println("優");
break;
case 9:
System.out.println("甲");
break;
case 8:
System.out.println("乙");
break;
case 7:
System.out.println("丙");
break;
case 6:
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
System.out.println("丁");
break;
default:
System.out.println("輸入錯誤!");
}
}
}
複製代碼
作者:
張彥承
時間:
2014-11-1 17:45
import java.io.Console;
public class ch12
{
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-11-4 20:23
import java.io.Console;
public class ch08
{
public static void main(String args[])
{
int score,level;
Console c=System.console();
System.out.print("請輸入你的成績:");
score=Integer.parseInt(c.readLine());
level=score/10;
switch(level)
{
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("輸入錯誤");
}
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2