標題:
switch 判斷式
[打印本頁]
作者:
tonyh
時間:
2019-7-3 09:18
標題:
switch 判斷式
運用 switch 語法,設計一個有趣的選擇題。
參考回應
1. 用跳的嗎?
2. 沒吃過豬肉也看過豬走路!
3. 你是豬啊?
4. 答對了!
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("輸入錯誤!");
}
}
}
複製代碼
作者:
古蕾娜
時間:
2019-7-3 10:05
import java.util.Scanner;
public class Ch03
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int ans;
System.out.println("<Brain Teasers>");
System.out.println("How many legs do pigs have? 1. One leg 2. 2 legs 3. 3 legs 4. 4 legs");
System.out.print("Your answer is: ");
ans=s.nextInt();
switch(ans)
{
case 1:
System.out.println("Do pigs hop now?");
break;
case 2:
System.out.println("Have you never seen a pig walk?");
break;
case 3:
System.out.println("You're the only pig here!");
break;
case 4:
System.out.println("Correct:)");
break;
default:
System.out.println("Wrong input!");
}
}
}
複製代碼
作者:
林宥杰
時間:
2019-7-3 10:05
import java.util.Scanner;
public class Ch01 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int ans;
System.out.println("問答");
System.out.println("請問豬有幾隻腳?(1)一 (2)二 (3)三 (4)四 ");
System.out.print("請回答");
ans=s.nextInt();
switch(ans)
{
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("錯誤");
}
}
}
複製代碼
作者:
李佳諭
時間:
2019-7-3 10:05
import java.util.Scanner;
public class Ch10 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int ans;
System.out.println("腦殘問答");
System.out.println("請問豬有幾隻腳?(1)一隻(2)兩隻(3)三隻(4)四隻 ");
System.out.print("請回答:");
ans=s.nextInt();
switch(ans){
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("輸入錯誤!");
}
}
}
複製代碼
作者:
陳致翰
時間:
2019-7-3 10:06
import java.util.Scanner;
public class Ch01 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int ans;
System.out.println("腦筋急轉彎:");
System.out.println("請問豬有幾隻腳? (1) 一隻 (2) 兩隻 (3) 三隻 (4) 四隻");
System.out.print("請回答: ");
ans= s.nextInt();
switch(ans)
{
case 1:
System.out.println("用跳的嗎?");
break;
case 2:
System.out.println("what?");
break;
case 3:
System.out.println("wow?");
break;
case 4:
System.out.println("GJ!");
break;
default:
System.out.println("輸入錯誤!");
}
}
}
複製代碼
作者:
陳柏銓
時間:
2019-7-3 10:07
import java.util.Scanner;
public class Ch113 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("1*3+2*4+3*5+4+8+7*9=? ");
System.out.println("(1)98 (2)100 (3)101 (4)99");
System.out.println("ANS: ");
int ans;
ans=s.nextInt();
switch (ans) {
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("錯誤");
}
}
}
複製代碼
作者:
李從赫
時間:
2019-7-3 10:08
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("輸入錯誤");
}
}
複製代碼
作者:
宋威廷
時間:
2019-7-3 10:08
import java.util.Scanner;
public class CH01 {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int answer;
System.out.println("question:");
System.out.println("請問豬有幾隻腳?(1)一隻(2)兩隻(3)三隻(4)四隻");
System.out.println("請回答:");
answer=s.nextInt();
switch(answer)
{
case 1:
System.out.println("are you kidding me?");
break;
case 2:
System.out.println("are you kidding me?");
break;
case 3:
System.out.println("are you kidding me?");
break;
case 4:
System.out.println("correct!congratulations");
break;
default:
System.out.println("error");
}
}
複製代碼
作者:
吳庭慈
時間:
2019-7-3 10:09
import java.util.Scanner;
public class Ch20 {
public static void main(String[] args) {
while(true){
Scanner s=new Scanner(System.in);
int ans;
System.out.println("~~腦殘問答~~");
System.out.println("請問豬有幾隻腳? (1)一隻 (2)兩隻(3)三隻(4)四隻");
System.out.print("請回答:");
ans=s.nextInt();
switch(ans)
{
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("輸入錯誤!");
}
}
}
}
複製代碼
作者:
蔡杰恩
時間:
2019-7-3 10:09
import java.util.Scanner;
public class Ch01 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int ans;
System.out.println("***腦殘問答***");
System.out.println("請問豬有幾隻腳?(1)一隻 (2)兩隻 (3)三隻 (4)四隻");
System.out.println("請回答:");
ans=s.nextInt();
switch(ans)
{
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("輸入錯誤!");
break;
}
}
}
複製代碼
作者:
古昇暘
時間:
2019-7-3 10:09
System.out.println("*** Brain Games ***");
System.out.println("How many legs does a pig have? (1)one leg (2)two legs (3)three legs (4) four legs");
System.out.print("Please enter the answer: ");
ans= s.nextInt();
switch(ans)
{
case 1:
{
System.out.println("Pigs jump?");
break;
}
case 2:
{
System.out.println("Are you a pig?");
break;
}
case 3:
{
System.out.println("Have you not seen a pig before?");
break;
}
case 4:
{
System.out.println("Correct!");
break;
}
default:
{
System.out.println("Input error");
}
}
}
}
複製代碼
作者:
葉子于
時間:
2019-7-3 10:10
import java.util.Scanner;
public class ch01 {
public static void main(String[] args) {
while(true){
Scanner s=new Scanner(System.in);
int ans;
System.out.println("<小米腦殘問答>");
System.out.println("請問豬有幾隻腳? (1)一隻 (2)兩隻 (3)三隻 (4)四隻 ");
System.out.println("請回答:");
ans=s.nextInt();
switch(ans)
{
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("輸入錯誤!");
}
}
}
}
複製代碼
作者:
李承洋
時間:
2019-7-3 10:10
import java.util.Scanner;
public class Ch13 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int answer;
System.out.print("致命選擇");
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("請重新輸入");
}
}
}
複製代碼
作者:
謝宗佑
時間:
2019-7-3 10:15
import java.util.Scanner;
public class Ch15 {
public static void main(String[] args){
Scanner s=new Scanner(System.in);
int answer;
System.out.print("<白痴回答>");
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("輸入錯誤!");
}
}
}
複製代碼
作者:
陳智鈞
時間:
2019-7-3 10:16
import java.util.Scanner;
public class Ch15 {
public static void main(String agrs[]){
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("輸入錯誤!");
}
}
}
複製代碼
作者:
李沛儒
時間:
2019-7-3 10:16
import java.util.Scanner;
public class Ch99 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int answer;
System.out.println("<問答>");
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("哩喜來亂ㄟ歐");
}
}
}
複製代碼
作者:
王煦
時間:
2019-7-3 10:16
import java.util.Scanner;
public class Ch01 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int answer;
System.out.println("您剛抽中了IPHONE X!");
System.out.println("只要回答下列問題,就能馬上額外加碼switch!");
System.out.println("有一艘船快沉船了,船上有436位乘客,468桶燃料,請問:韓國瑜繼續當高雄市長的機率是多少?(1)100趴(2)韓總不會耽誤市政啦(3)放眼世界,征服宇宙(4)紫色,因為外星人不會戴帽子");
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("你再繼續亂打沒關係");
}
}
}
複製代碼
作者:
張啟廣
時間:
2019-7-3 10:16
import java.util.Scanner;
public class Ch01
{
public static void main(String[] args)
{
while(true)
{
Scanner s=new Scanner(System.in);
int ans;
System.out.println("****白癡問答,不會去撞牆****");
System.out.println("請問正常情況下,你(人類)有腳?");
System.out.println("(1)1隻(2)2隻(3)3隻(4)6隻");
System.out.println("請民政局局長回答,高雄發大財: ");
ans=s.nextInt();
switch(ans)
{
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();
}
}
}
複製代碼
作者:
陳璽安
時間:
2019-7-3 10:16
import java.util.Scanner;
public class Ch13 {
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("不可能傻B");
break;
case 2:
System.out.println("中央沒經費");
break;
case 3:
System.out.println("館長不開心");
break;
case 4:
System.out.println("凍不了阿ㄚㄚㄚㄚㄚ!");
break;
default:
System.out.println("輸入錯誤!");
}
}
}
複製代碼
作者:
蔡杰希
時間:
2019-7-3 10:17
import java.util.Scanner;
public class Ch01 {
public static void main(String[]args){
Scanner s=new Scanner(System.in);
int ans;
while(true){
System.out.println("<小米腦殘問答>");
System.out.println("請問豬有幾隻腳? (1)一隻(2)兩隻(3)三隻(4)四隻");
System.out.print("請回答:");
ans=s.nextInt();
switch(ans)
{
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("輸入錯誤!");
}
}
}
}
複製代碼
作者:
劉欽文
時間:
2019-7-3 10:19
import java.util.Scanner;
public class Ch01 {
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("輸入錯誤!");
}
}
}
複製代碼
作者:
賴駿榮
時間:
2019-7-3 10:21
package ch01;
import java.util.Scanner;
public class ch01
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int ans;
System.out.println("問答");
System.out.println("高通旗艦處理器是以下哪一個?(1)S710(2)MTK670(3)A12X(4)S855");
System.out.println("回答");
ans=s.nextInt();
switch(ans)
{
case 1:
System.out.println("要猜也猜C沒人在猜A");
break;
case 2:
System.out.println("要猜也猜C沒人在猜A");
break;
case 3:
System.out.println("猜c不一定是答案");
break;
case 4:
System.out.println("對了");
break;
default:
System.out.println("哪裡有這個選項!!");
}
}
}
複製代碼
回復
1#
tonyh
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2