im trying to generate a random number and have the user guess it until they get it right here is the code:
import java.util.Scanner;
import java.util.Random;
public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int number;
number = GetNumber(5);
boolean win = false;
int guess;
guess = GetGuess(5);
while( win = false)
{
if( guess > number)
{
System.out.print("Too high. Try Again");
guess = GetGuess(5);
}
if( guess < number)
{
System.out.print("Too low. Try Again");
guess = GetGuess(5);
}
}
if( guess == number)
{
win = true;
System.out.print("Congratulations you win");
}
}
public static int GetGuess(int guess)
{
Scanner input = new Scanner(System.in);
System.out.print("Guess a number between 1 and 100: ");
guess = input.nextInt();
return guess;
}
public static int GetNumber(int number)
{
Random rand = new Random();
number = rand.nextInt(100) + 1;
return number;
}
}
and this is the output im getting:
Guess a number between 1 and 100: 67
Press any key to continue . . .
I am just a beginner at using java programming and i am using Textpad if that makes any difference at all.