- int player = 0;
-
- System.out.println("請輸入您的選擇:(0=剪刀;1=石頭;2=布");
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String bufstr = br.readLine();
-
- player = Integer.parseInt(bufstr); //把玩家輸入的值存到player中
-
- //int Computer = 0;
- double rd = Math.random();
-
- if( player == 0) //玩家出剪刀
- {
- if( rd < 0.33 ) //電腦出剪刀
- {
- System.out.println("rd: " + rd + "電腦出剪刀" + ",平手");
- }
- else if( rd < 0.66) //電腦出石頭
- {
- System.out.println("rd: " + rd + "電腦出石頭" + ",您輸了");
- }
- else //電腦出布
- {
- System.out.println("rd: " + rd + "電腦出布" + ",您贏了");
- }
- }
- else if( player == 1) //玩家出石頭
- {
-
- }
- else //玩家出布
- {
-
- }
-
複製代碼 |