如果可能的话需要一些指导。对爪哇来说是新手。不知道为什么下面的代码石头,纸,剪刀游戏不起作用。欢迎您提出任何建议或建议。我知道在这个伟大的论坛上有很多例子--但我仍然掌握着基本知识。谢谢。
import java.util.*;
import java.util.Scanner;
import java.util.Random;
public class Game
{
public static void main (String[] args){
int NumberofRoundsPlayed;
int NumberofRoundsWonbyHuman = 0;
Scanner Keyboard = new Scanner (System.in
System.out.println("DO YOU WANT TO PLAY ROCK PAPER SCISSORS- Y/N");
String HumanPlaying = Keyboard.nextLine();
if(HumanPlaying ==("No"))
{
System.out.println("Game Over");
System.exit(0);}
}
int Paper = 1;
int Scissor = 2;
int Rock = 3;
int HumanSelection;
int humanroundsWon =0;
System.out.println("HOW MANY ROUNDS DO YOU WANT TO PLAY");
NumberofRoundsPlayed = Keyboard.nextInt();
while (NumberofRoundsPlayed <= NumberofRoundsPlayed +1)
{
Scanner Computer = new Scanner (System.in);
Random rand = new Random();
int ComputerChoice =Computer.nextInt(3)+1;
System.out.println(ComputerChoice);
System.out.println("Select 1 for Paper, 2 for Scissor or 3 for Rock");
HumanSelection = Keyboard.nextInt();
//SEE WHO WINS
If (ComputerChoice== 1)
{
If (HumanSelection==1)
{
System.out.println("Computer and Human Have Tied");
} Else if (HumanSelection==2)
{
System.out.println("Person Wins");
humanroundsWon == humanroundsWon+1;
}
Else if (HumanSelection==3)
{
System.out.println("Computer Wins");
}
Else if (ComputerChoice==2)
{
If (HumanSelection==1)
{
System.out.println("computer Wins");
}
Else if (HumanSelection==2)
{
System.out.println("Computer and Person Have Tied");
}
Else if (HumanSelection==3)
{
System.out.println("Person Wins");
humanroundsWon == humanroundsWon+1;
}
}
Else if (ComputerChoice==3)
{
}
If (HumanSelection==1)
{
System.out.println("Person Wins");
humanroundsWon == humanroundsWon+1;
}
Else if (HumanSelection==2)
{
{ System.out.println("Computer Wins");
}
Else if (HumanSelection==)
{
System.out.println("Tie");
roundsWon == roundsone+1;
}
}
}
}
}
}
System.out.println("Game Over");
System.exit(0);}发布于 2016-04-08 05:09:51
这是代码,如果我对您的场景的理解是正确的话。当您提出问题时,请指出code实际上需要执行什么,以便其他人可以帮助您。还有一点提示,尝试使用像eclipse这样的IDE来帮助您编写代码。您可以找到它,这里只需根据您的平台架构( 32bit或64bit)下载Eclipse IDE for Java EE Developers并提取zip文件。然后运行eclipse IDE --它很简单
import java.util.*;
import java.util.Scanner;
import java.util.Random;
public class Game
{
public static void main (String[] args){
int NumberofRoundsPlayed;
int NumberofRoundsWonbyHuman = 0;
Scanner Keyboard = new Scanner (System.in);
System.out.println("DO YOU WANT TO PLAY ROCK PAPER SCISSORS- Y/N");
String HumanPlaying = Keyboard.nextLine();
if(HumanPlaying.equals("No"))
{
System.out.println("Game Over");
System.exit(0);
}
int Paper = 1;
int Scissor = 2;
int Rock = 3;
int HumanSelection;
int humanroundsWon =0;
System.out.println("HOW MANY ROUNDS DO YOU WANT TO PLAY");
NumberofRoundsPlayed = Keyboard.nextInt();
while (NumberofRoundsPlayed < NumberofRoundsPlayed++)
{
Scanner Computer = new Scanner (System.in);
Random rand = new Random();
int ComputerChoice =Computer.nextInt()+1;
System.out.println(ComputerChoice);
System.out.println("Select 1 for Paper, 2 for Scissor or 3 for Rock");
HumanSelection = Keyboard.nextInt();
//SEE WHO WINS
if (ComputerChoice== 1)
{
if (HumanSelection==1)
{
System.out.println("Computer and Human Have Tied");
}
else if (HumanSelection==2)
{
System.out.println("Person Wins");
humanroundsWon++;
}
else if (HumanSelection==3)
{
System.out.println("Computer Wins");
}
}
else if (ComputerChoice==2)
{
if (HumanSelection==1)
{
System.out.println("computer Wins");
}
else if (HumanSelection==2)
{
System.out.println("Computer and Person Have Tied");
}
else if (HumanSelection==3)
{
System.out.println("Person Wins");
humanroundsWon++;
}
}
else if (ComputerChoice==3)
{
if (HumanSelection==1)
{
System.out.println("Person Wins");
humanroundsWon++;
}
else if (HumanSelection==2)
{
System.out.println("Computer Wins");
}
else if (HumanSelection==3)
{
System.out.println("Tie");
}
}
}
System.out.println("Game Over");
System.exit(0);
}
}发布于 2016-04-08 04:40:42
如果它不编译,Scanner Keyboard = new Scanner (System.in是一个不完整的语句。
https://stackoverflow.com/questions/36491600
复制相似问题