I've made a program that asks the user for a number and then checks if it is equal, less or greater than a random number. A siple guessing game. It works perfectly but I would like to display the output on the same line as the input but I can't figure out how to do this.
Ok, I've picked a number between 1 and 100. What is your first guess?
Guess 1: 36
<
Guess 2: 50
>
Guess 3: 46
That is correct. The hidden number is 46.
This is how I want it to look like:
Guess 1: 36 <
Guess 2: 50 >
Guess 3: 46 That is correct. The hidden number is 46.
How do I do this? The cursor is moving down after the input when I use Scanner.nextInt();
This is my current code:
while (!isCorrect) {
System.out.print("Guess " + guessCount + ": ");
currentGuess = input.nextInt();
if (currentGuess == randomNumber) {
isCorrect = true;
System.out.println("That is correct. The hidden number was " + randomNumber);
}
else if (currentGuess > randomNumber) {
System.out.println(" >");
++guessCount;
}
else if (currentGuess < randomNumber) {
System.out.println(" <");
++guessCount;
}
}