package game;import java.util.Scanner;/*?* 實現功能:玩家在自己選擇出石頭,剪刀或布,電腦隨機給出一個選擇并輸出提示,然后比較輸贏3?*/public class shitoujiandaobu {?public static void main(String[] args) {??shitoujiandaobu hello=new shitoujiandaobu();??Scanner input =new Scanner(System.in);??System.out.println("請玩家輸入:0,1或2;0=剪刀,1=石頭,2=布");??int player =input.nextInt();??int computer;??if(player==0){???System.out.println("您選擇的是剪刀");??}??else if(player==1){???System.out.println("您選擇的是石頭");??}??else if(player==2){???System.out.println("您選擇的是布");??}??else{???System.out.println("輸入有誤,請您重入0,1或2;0=剪刀,1=石頭,2=布;");??}?? computer=(int)(Math.random()*3);?? if(player==0){???System.out.println("電腦選擇的是剪刀");??}?? else if(computer==1){???System.out.println("電腦選擇的是石頭");??}?? else if(computer==2){???System.out.println("電腦選擇的是布");??}??hello.compare(player, computer);?????}?public void compare(int a,int b)?{???if(a==b)??{???System.out.println("我們平了");??}??else if(a==0&&b==2||a==1&&b==0||a==2&b==1){???System.out.println("你贏了");??}??else{???System.out.println("你輸了");??}?}}
添加回答
舉報
0/150
提交
取消