標題:
switch 判斷式
[打印本頁]
作者:
tonyh
時間:
2012-10-5 21:13
標題:
switch 判斷式
import java.lang.*;
import java.io.Console;
public class ch09
{
public static void main(String args[])
{
Console console=System.console();
int score;
int level;
System.out.print("請輸入你的成績: ");
score=Integer.parseInt(console.readLine());
level=score/10;
switch(level)
{
case 10:
System.out.println("哇滿分!太神了!");
break; //跳出
case 6: case 7: case 8: case 9:
System.out.println("恭喜你及格了!");
break;
case 0: case 1: case 2: case 3: case 4: case 5:
System.out.println("不及格!下次再努力!");
break;
default:
System.out.println("輸入錯誤!");
}
}
}
複製代碼
作者:
孫家祥
時間:
2012-10-5 21:20
回復
1#
tonyh
import java.io.Console;
public class ch09
{
public static void main(String args[])
{
Console keyin=System.console();
int int1;
Float ft2;
System.out.print("請你的成績:");
int1=Integer.parseInt(keyin.readLine());
int1=int1/10;
switch(int1)
{
case 10:
System.out.print("恭喜您當老師了!");
break;
case 9: case 8: case 7: case 6:
System.out.print("恭喜您及格了!");
break;
case 5: case 4: case 3: case 2: case 1:
System.out.print("恭喜您重修了!");
break;
case 0:
System.out.print("恭喜您可以回家了!");
break;
default:
System.out.print("恭喜您亂打了!");
}
}
}
複製代碼
作者:
晏有聰
時間:
2012-10-5 21:21
import java.io.Console;
public class ch09
{
public static void main (String showdemo[])
{
Console console=System.console();
int score;
int level;
System.out.print("Please input your score =");
score=Integer.parseInt(console.readLine());
level=score/10;
switch(level)
{
case 10 :
System.out.println("有作弊嗎? 太神了");
break;
case 9: case 8: case 7:case 6:
System.out.println("恭喜及格了!!");
break;
case 5:case 4:case 3:case 2:case 1:
System.out.println("成績不及格!!");
break;
case 0:
if (score >0)
{
System.out.println("成績不及格!!");
}
else
{
System.out.println("鴨蛋喔!!");
}
break;
default :
System.out.println("輸入錯誤,你是來亂的嗎?");
}
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2