导入java.util。*; 公共类HelloWorld
{
public static void main(String []args)
{
int score =0;
int noOfGames =0;
int noOfCorrectedGames =0;
String name;
int age;
int ran=0;
int guessno=0;
int round_count=0;
Scanner keyboard = new Scanner(System. in);
System.out.println("Enter your Name:");
name = keyboard.next();
System.out.println("Enter your age in Numeric:");
age = keyboard.nextInt();
//System.out.println("Random value is " + ran);
if(age<7 && age>=4)
{
ran=randomNumberInRange(1, 20);
}
else if(age<12 && age>=7)
{
ran=randomNumberInRange(1, 25);
}
else if(age>=12)
{
ran=randomNumberInRange(1, 30);
}
else if(age<4)
{
System.out.println("You are Strictly prohibited to use this " +
"application including the laptop");
System.exit(0);
}
for(int y=1;y<10;y++) //Play Till you Die
{
noOfGames = y;
if(age<7 && age>=4)
{
ran=randomNumberInRange(1, 20);
}
else if(age<12 && age>=7)
{
ran=randomNumberInRange(1, 25);
}
else if(age>=12)
{
ran=randomNumberInRange(1, 30);
}
else if(age<4)
{
System.out.println("You are Strictly prohibited to use this " +
"application including the laptop");
System.exit(0);
}
for (int i=1;i<11;i++) // every student get a 10 attempts
{
round_count=i;
System.out.println("Guess the Magical No(Numeric):");
guessno = keyboard.nextInt();
if(guessno==ran) //If Correct Answer
{
if(i>=1 && i<=3)
{
score=5;
}
else if(i>=4 && i<=6)
{
score=3;
}
else if(i>=7 && i<=10)
{
score=1;
}
noOfCorrectedGames++;
System.out.println("-------------------GAME OVER --------------------");
System.out.println("Do you want to Play again? Enter P; Do you want to Exit? Enter E; :");
String result = keyboard.next();
if(result.equals("E"))
{
print_deadgame_results();
System.exit(0);
}
else
{
break;
}
}
else //If Wrong Answer
{
if(ran >guessno)
{
System.out.println("GO HIGHER !");
}
else if(ran <guessno)
{
System.out.println("GO LOWER !");
}
}
}
if(round_count==10)
{
System.out.println("-------------------GAME OVER --------------------");
System.out.println("Do you want to Play again? Enter P; Do you want to Exit? Enter E; :");
String result = keyboard.next();
if(result=="E")
{
print_deadgame_results();
System.exit(0);
}
else
{
}
}
}
print_deadgame_results();
}
public static int randomNumberInRange(int min, int max)
{
Random random = new Random();
return random.nextInt((max - min) + 1) + min;
}
public static void print_deadgame_results()
{
System.out.println("=================== Final Score =======================");
System.out.println("Total number of games played : " + noOfGames);
System.out.println("Total number of games where correct guesses were made : " +noOfCorrectedGames);
System.out.println("Hello "+ name +", you scored "+ score +" out of possible "+ noOfGames +".");
}
}
HelloWorld.java:160:错误:找不到符号
System.out.println(“玩过的游戏总数:” + noOfGames);
^
符号:变量noOfGames
位置:类HelloWorld
HelloWorld.java:161:错误:找不到符号
System.out.println(“做出正确猜测的游戏总数:” + noOfCorrectedGames);
^
符号:变量noOfCorrectedGames
位置:类HelloWorld
HelloWorld.java:162:错误:找不到符号
System.out.println(“ Hello” + name +“,您在可能的” + noOfGames +“中得分为” + score +“。);
^
符号:变量名
位置:类HelloWorld
HelloWorld.java:162:错误:找不到符号
System.out.println(“ Hello” + name +“,您在可能的” + noOfGames +“中得分为” + score +“。);
^
符号:可变分数
位置:类HelloWorld
HelloWorld.java:162:错误:找不到符号
System.out.println(“ Hello” + name +“,您在可能的” + noOfGames +“中得分为” + score +“。);
^
符号:变量noOfGames
位置:HelloWorld类
答案 0 :(得分:0)
noOfGames
是您的main
方法中的局部变量。如果要在print_deadgame_results
方法中使用它,则应将其作为参数传递给它,或将其转换为静态成员。