import java.util.Scanner; public class ScissorsRockPaper {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in); System.out.println("欢迎来玩剪刀石头布游戏!"); System.out.println("请输入你的选择:剪刀、石头、布"); String PlayerChoice = scanner.nextLine();
String Choices[] = {"石头","剪刀","布"}; int ComputerChoiceInt = (int) (Math.random()*3); String ComputerChoice = Choices[ComputerChoiceInt]; System.out.println("电脑选择了:" +ComputerChoice);
switch (PlayerChoice){
case "剪刀":
if (ComputerChoice.equals("剪刀"))
{
System.out.println("平局"); }
else if (ComputerChoice.equals("石头"))
System.out.println("电脑胜利,你输了"); }
else if (ComputerChoice.equals("布"))
System.out.println("恭喜你,你赢了"); }
break;
case "石头":
if (ComputerChoice.equals("石头"))
System.out.println("电脑胜利,你输了"); }else if (ComputerChoice.equals("剪刀"))
case "布":
if (ComputerChoice.equals("布"))
else if (ComputerChoice.equals("剪刀"))
System.out.println("电脑胜利,你输了"); }else if (ComputerChoice.equals("石头"))
break; default:
System.out.println("请输入符合要求的选项"); }
scanner.close();
}
Sign in to make a reply
Ashen One
import java.util.Scanner;
public class ScissorsRockPaper {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("欢迎来玩剪刀石头布游戏!");
System.out.println("请输入你的选择:剪刀、石头、布");
String PlayerChoice = scanner.nextLine();
String Choices[] = {"石头","剪刀","布"};
int ComputerChoiceInt = (int) (Math.random()*3);
String ComputerChoice = Choices[ComputerChoiceInt];
System.out.println("电脑选择了:" +ComputerChoice);
switch (PlayerChoice){
case "剪刀":
if (ComputerChoice.equals("剪刀"))
{
System.out.println("平局");
}
else if (ComputerChoice.equals("石头"))
{
System.out.println("电脑胜利,你输了");
}
else if (ComputerChoice.equals("布"))
{
System.out.println("恭喜你,你赢了");
}
break;
case "石头":
if (ComputerChoice.equals("石头"))
{
System.out.println("平局");
}
else if (ComputerChoice.equals("布"))
{
System.out.println("电脑胜利,你输了");
}else if (ComputerChoice.equals("剪刀"))
{
System.out.println("恭喜你,你赢了");
}
break;
case "布":
if (ComputerChoice.equals("布"))
{
System.out.println("平局");
}
else if (ComputerChoice.equals("剪刀"))
{
System.out.println("电脑胜利,你输了");
}else if (ComputerChoice.equals("石头"))
{
System.out.println("恭喜你,你赢了");
}
break;
default:
System.out.println("请输入符合要求的选项");
}
scanner.close();
}
}