標題:
switch 判斷式 (二)
[打印本頁]
作者:
tonyh
時間:
2020-2-3 09:10
標題:
switch 判斷式 (二)
本帖最後由 tonyh 於 2020-2-3 09:26 編輯
將題目的答案選項改為以ABCD表示,使用者輸入大寫或小寫都要能接受。
import java.util.Scanner;
public class Ch11 {
public static void main(String[] args) {
String ans;
Scanner s=new Scanner(System.in);
System.out.println("<腦殘問答>");
while(true)
{
System.out.println("豬有幾隻腳? (A)1 (B)2 (C)3 (D)4");
System.out.print("請作答: ");
ans=s.nextLine();
switch(ans)
{
case "A":
case "a":
case "1":
System.out.println("用跳的嗎?");
break;
case "B":
System.out.println("沒吃過豬肉也看過豬走路!");
break;
case "C":
System.out.println("你是豬啊?");
break;
case "D":
System.out.println("答對了!");
break;
default:
System.out.println("輸入錯誤!");
}
System.out.println();
}
}
}
複製代碼
作者:
蔡承翰
時間:
2020-2-3 09:36
import java.util.Scanner;
public class Ch01 {
public static void main(String[] args) {
String ans;
Scanner s=new Scanner(System.in);
System.out.println("腦殘問答");
while(true){
System.out.println("請問豬有幾隻腳? (A)1隻(B)2隻(C)3隻(D)4隻");
System.out.print("請作答:");
ans=s.nextLine();
switch (ans) {
case "A":
case "a":
case "1":
System.out.println("用跳的嗎?");
break;
case "B":
case "b":
case "2":
System.out.println("沒吃過豬肉也看過豬走路!");
break;
case "C":
case "c":
case "3":
System.out.println("你是豬啊?");
break;
case "D":
case "d":
case "4":
System.out.println("答對了!");
break;
default:
System.out.println("輸入錯誤!");
break;
}
}
}
}
複製代碼
作者:
張宸翔
時間:
2020-2-3 09:37
import java.util.Scanner;
public class Ch11 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
String ans;
System.out.println("腦殘問答");
while(true)
{
System.out.println("豬有幾隻腳? (A)1隻 (B)2隻 (C)3隻 (D)4隻");
System.out.print("請回答: ");
ans=s.nextLine();
switch(ans)
{
case"A":
case"a":
case"1":
System.out.println("用跳的嗎?");
break;
case"B":
case"b":
case"2":
System.out.println("沒吃過豬肉也看過豬走路!");
break;
case"C":
case"c":
case"3":
System.out.println("你是豬阿?");
break;
case"D":
case"d":
case"4":
System.out.println("答對了!");
break;
default:
System.out.println("輸入錯誤!");
}
}
}
}
複製代碼
作者:
蘇宜貞
時間:
2020-2-3 09:39
import java.util.Scanner;
public class Ch01 {
public static void main(String[] args) {
while(true)
{
Scanner s=new Scanner(System.in);
String answer;
System.out.println("請問豬有幾隻腳?");
System.out.print("請作答: ");
answer=s.nextLine();
switch(answer)
{
case "A":
case "a":
case "1":
System.out.println("用跳的嗎?");
break;
case "B":
case "b":
case "2":
System.out.println("沒吃過豬肉也看過豬走路!");
break;
case "C":
case "c":
case "3":
System.out.println("你是豬啊!");
break;
case "D":
case "d":
case "4":
System.out.println("答對!");
break;
default:
System.out.println("輸入錯誤!");
}
}
}
}
複製代碼
作者:
盧弘毅
時間:
2020-2-3 09:41
import java.util.Scanner;
public class Ch11 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
String ans;
System.out.println("<腦殘問答>");
while(true)
{
System.out.println("請問豬有幾隻腳?(A)1 (B)2 (C)3 (D)4");
System.out.println("請作答:");
ans=s.nextLine();
switch(ans)
{
case "A":
case "a":
case "1":
System.out.println("用跳的嗎?");
break;
case "B":
case "b":
case "2":
System.out.println("沒吃過豬肉也看過豬走路!");
break;
case "C":
case "c":
case "3":
System.out.println("你是豬啊?");
break;
case "D":
case "d":
case "4":
System.out.println("答對了!");
break;
default:
System.out.println("輸入錯誤");
}
}
}
}
複製代碼
作者:
蘇行一
時間:
2020-2-3 09:44
import java.util.Scanner;
public class Ch10 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
String ans;
System.out.println("<腦殘問答>");
while(ture){
System.out.println("請問豬有幾隻腳: (A)一隻 (B)兩隻 (C)三隻 (D)四隻");
System.out.print("請回答: ");
ans=s.nextLine();
switch(ans)
{
case"A":
case"a":
case"1":
System.out.println("用跳的嗎?");
break;
case"B":
case"b":
case"2":
System.out.println("沒吃過豬肉也看過豬走路!");
break;
case"C":
case"c":
case"3":
System.out.println("你是豬啊?");
break;
case"D":
case"d":
case"4":
System.out.println("答對了!");
break;
default;
System.out.println("輸入錯誤!");
}
}
}
}
複製代碼
作者:
劉家銘
時間:
2020-2-3 09:45
import java.util.Scanner;
public class Ch11
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
while(true)
{
String ans;
System.out.println("<腦殘問答>");
System.out.println("請問豬有幾隻腳? (A)1 (B)2 (C)3 (D)4");
System.out.println("請作答: ");
ans=s.nextLine();
switch (ans)
{
case "A":
case "a":
case "1":
System.out.println("用跳的嗎?");
break;
case "B":
case "b":
case "2":
System.out.println("沒吃過豬肉也看過豬走路!");
break;
case "C":
case "c":
case "3":
System.out.println("你是豬啊?");
break;
case "D":
case "d":
case "4":
System.out.println("答對了!");
break;
default:
System.out.println("輸入錯誤!");
}
}
}
}
複製代碼
作者:
邱翊博
時間:
2020-2-3 09:45
package hello;
import java.util.Scanner;
public class hello {
public static void main(String[] args) {
String ans;
Scanner s=new Scanner(System.in);
System.out.println("<腦殘>");
while(true)
{
System.out.println("請問豬有幾隻腳?(A)一隻(B)兩隻(C)三隻(D)四隻");
System.out.print("請回答: ");
ans=s.nextLine();
switch(ans)
{
case "A":
System.out.println("殘障豬是嗎?");
break;
case "B":
System.out.println("可憐哪~");
break;
case "C":
System.out.println("總目標是發大財!");
break;
case "D":
System.out.println("正確?");
break;
default:
System.out.println("輸入錯誤");
}
}
}
}
複製代碼
作者:
楊秉樺
時間:
2020-2-3 09:46
import java.util.Scanner;
public class Ch11 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
String ans;
while (true)
{
System.out.println("<腦殘問題>");
System.out.println("請問豬有幾隻腳? <A>1 <B>2 <C>3 <D>4 ");
System.out.print("請回答: ");
ans=s.next();
switch(ans)
{
case "A":
case "a":
case "1":
System.out.println("用跳的嗎?");
break;
case "B":
case "b":
case "2":
System.out.println("沒吃過豬肉也看過豬走路");
break;
case "C":
case "c":
case "3":
System.out.println("你是豬啊!");
break;
case "D":
case "d":
case "4":
System.out.println("答對了!");
break;
default :
System.out.println("輸入錯誤");
break;
}
System.out.println();
}
}
}
複製代碼
作者:
黃煜城
時間:
2020-2-3 09:47
import java.util.Scanner;
public class Ch18 {
public static void main(String[] args) {
String ans;
Scanner s=new Scanner(System.in);
System.out.println("白癡問答:");
System.out.println("請問豬有幾隻腳? (A)一隻 (B)兩隻 (C)三隻 (D)四隻");
System.out.print("請作答:");
ans=s.nextLine();
switch(ans)
{
case "A":
case "a":
case "1":
System.out.println("你是外星人嗎?");
break;
case "B":
case "b":
case "2":
System.out.println("原來豬可以站起來阿~");
break;
case "C":
case "c":
case "3":
System.out.println("殘疾[豬]士");
break;
case "D":
case "d":
case "4":
System.out.println("Good job!");
break;
default:
System.out.println("你打錯了 請重新輸入!");
}
}
}
複製代碼
作者:
沙芃妘
時間:
2020-2-3 09:51
import java.util.Scanner;
public class Ch10
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int answer;
System.out.println("<小米腦殘問答>");
System.out.println("請問豬有幾隻腳? (1)一隻(2)兩隻(3)三隻(4)四隻");
System.out.print("請回答:");
answer=s.nextInt();
switch(answer)
{
case 1:
System.out.println("用跳的嗎?");
break;
case 2:
System.out.println("沒吃過豬肉也看過豬走路!");
break;
case 3:
System.out.println("你是豬啊?");
break;
case 4:
System.out.println("答對了!");
break;
default:
System.out.println("輸入錯誤!");
{
System.out.println();
}
}
}
}
複製代碼
作者:
陳梓瑜
時間:
2020-2-3 09:52
import java.util.Scanner;
public class Ch10
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int answer;
System.out.println("<腦殘問答>");
System.out.println("請問朱有幾隻腳?(1)一隻(2)兩隻(3)三隻(4)四隻");
System.out.println("請回答: ");
answer=s.nextInt();
switch(answer)
{
case 1:
System.out.println("用跳的嗎?");
break;
case 2:
System.out.println("沒吃握豬肉也看過豬走路!");
break;
case 3:
System.out.println("你是朱阿?");
break;
case 4:
System.out.println("答對了");
break;
default:
System.out.println("輸入錯誤");
}
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2