*3.17(游戏:剪刀、石头、布)编写可以玩流行的剪刀-石头-布游戏的程序。(剪刀可以剪布,石头可以砸剪刀,而布可以包石头。)程序提示用户随机产生一个数,这个数为0、1或者2,分别表示石头、剪刀和布。程序提示用户输入值0、1或者2,然后显示一条消息,表明用户和计算机谁赢了游戏,谁输了游戏,或是打成平手。
下面是运行示例:
scissor(0),rock(1),paper(2): 1
The computer is scissor.You are rock.You won
scissor(0),rock(1),paper(2): 2
The computer is paper.You are paper too.It is a draw
*3.17(Game: scissor, rock, paper) Write a program that plays the popular scissor–rock–paper game. (A scissor can cut a paper, a rock can knock a scissor, and a paper can wrap a rock.) The program randomly generates a number 0, 1, or 2 representing scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and displays a message indicating whether the user or the computer wins, loses, or draws.
Here are sample runs:
scissor(0),rock(1),paper(2): 1
The computer is scissor.You are rock.You won
scissor(0),rock(1),paper(2): 2
The computer is paper.You are paper too.It is a draw
下面是参考答案代码:
import java.util.*;
public class ScissorRockPaperQuestion17 {
public static void main(String[] args) {
// Generate the computer's guess
final int userGuess,computerGuess = (int)(Math.random()*3);
// Prompt the user to enter a guess
System.out.print("scissor(0),rock(1),paper(2): ");
Scanner input = new Scanner(System