I'm trying to create a Java guessing game, but the first part I'm working on is having issues and I would like some help. The program first asks a user to input a number, then the program asks them to confirm whether their number is what they inputted.
If they enter yes to whether they inputted the correct number, it currently just outputs "bru".
If no is inputted then they re-enter the input number and the cycle will go on until the user correctly inputs their number and confirms it.
I'm trying to accomplish this with a while
loop.
Unfortunately when I run the program everything works fine until I'm asked to enter yes or no to confirm my number. If I enter yes it still asks for me to re-enter the number. But if I enter no and then I say no again confirming my number it gives me the output for when I confirm that I inputted the correct number.
import java.util.Scanner;
import java.util.Random;
public class Assignment6 {
public static void main(String args[]) {
Scanner input = new Scanner( System.in );
System.out.print ( "Please enter the upper bound of the secret number.");
int UpperBound = input.nextInt();
System.out.print ( "The UpperBound you entered is" + " " + UpperBound + "." + "Is that correct?" + "" + "If yes please enter yes, if not please enter no.");
String TrueOrFalse = input.next();
while (TrueOrFalse == "no" | TrueOrFalse == "No");
{
System.out.print ( "Please enter the new upper bound of the secret number.");
UpperBound = input.nextInt();
System.out.print ( "The UpperBound you entered is" + " " + UpperBound + "." + " " + "Is that correct. If yes please enter yes, if not please enter no.");
TrueOrFalse = input.next();
}
System.out.print ("Bru");
}
}