所以,当我运行这个程序时,我可以输入值,但在输入完值后,它不会执行switch语句来告诉我谁赢了。我还没有放入所有的情况,但我想测试一下,什么也没发生。我曾尝试将y设为随机值,但那样并不起作用,所以我只能让用户进行输入。最终,我需要让人类与计算机对战。
import java.util.Scanner;
import java.util.Random;
public class rock{
public static void main(String[] args) {
int x;
int y;
Random randomGenerator = new Random();
Scanner input= new Scanner(System.in);
System.out.print("Human player: Enter 0 for rock, 1 for scissors, 2 for paper, 3 for lizard, 4 for spock:");
x=input.nextInt();
System.out.print("Computer player: Enter 0 for rock, 1 for scissors, 2 for paper, 3 for lizard, 4 for spock:");
y = input.nextInt();
switch(x)
{
case '0':
switch (y)
{
case '1':
System.out.print("Human Wins computer chose scissors!");
break;
case '2':
System.out.println("Human wins computer chose paper!");
break;
case '0':
System.out.println("Draw!");
break;
case '3':
System.out.println("Human Wins with Lizard!");
break;
case '4':
System.out.println("Computer Wins with Spock!");
break;
}
}
switch (x)
{
case '1':
switch(y)
{
case '1':
System.out.print("Human Wins computer chose scissors!");
break;
case '2':
System.out.println("Human wins computer chose paper!");
break;
case '0':
System.out.println("Draw!");
break;
case '3':
System.out.println("Human Wins with Lizard!");
break;
case '4':
System.out.println("Computer Wins with Spock!");
break;
}
}
switch (x)
{
case '2':
switch (y)
{
case '1':
System.out.print("Human Wins computer chose scissors!");
break;
case '2':
System.out.println("Human wins computer chose paper!");
break;
case '0':
System.out.println("Draw!");
break;
case '3':
System.out.println("Human Wins with Lizard!");
break;
case '4':
System.out.println("Computer Wins with Spock!");
break;
}
}
}
}