Greetings from a new Java coder.
I have ran unto a problem that i cant seem too solve on my own.
And since next class is on Tuesday i hope you can help me out.
When i compile this i get an error on "Line 57 : "Scan cannot be resolved""
And i am wondering why thats the case.
Well cheers for taking your time
//Martin
import java.util.Scanner;
import java.util.Random;
import java.io.*;
public class Game {
public static void main(String[] args) {
int tries = 0;
Random random = new Random();
boolean playAgain = true;
Scanner input = new Scanner(System.in);
System.out.println("Guess a number between 0 and 1000");
while (playAgain)
{
boolean okinput;
int number = random.nextInt(1000) + 1;
String answer;
int guess = -1;
//Ask the user to guess the number
System.out.println("\nEnter your guess: ");
guess = input.nextInt();
okinput = true;
if (guess < 0 || guess > 1000) {
System.out.println("Try between 0 and 1000 instead");
okinput = false;
}
while (!okinput);
{
if (guess > number) {
System.out.println("Your guess is too high");
tries++;
}
else if (guess < number) {
System.out.println("Your guess is too low");
tries++;
}
else {
System.out.println("Correct!");
tries++;
}
// ending loop
while (guess == number) {
System.out.println("You guess the correct answer in " + tries + " tries");
break;
do { System.out.print("\nPlay again? (Y or N)" );
answer = scan.next();
okinput = true;
if (answer.equalsIgnoreCase("Y"));
else if (answer.equalsIgnoreCase("N"))
playAgain = false;
else
okinput = false;
} while (!okinput);
System.out.println("\nThank you for playing!");
}
}
}
}
}