Change it to

...
String input;
do
{
    input = scan.next();
    if(input.equals("enter") || input.equals("Enter"))
    {
        System.out.println("You have entered the house.");
    }
...
Answer from Dacaspex on Stack Overflow
🌐
Quora
quora.com › How-can-you-do-a-do-while-loops-in-Java-with-user-input-and-statement
How to do a do while loops in Java with user input and statement - Quora
... A do‑while loop in Java executes ... combined with user input (Scanner), it’s commonly used to prompt the user and continue until they choose to stop or enter a sentinel value....
Discussions

java - Do-While loop with user input - Stack Overflow
How would I allow user input to select one of four methods that print a certain pattern using a do-while loop and no input validation is required. The user just needs to select a number from 1-4 that More on stackoverflow.com
🌐 stackoverflow.com
March 27, 2018
Pausing a while loop to get user input, help

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

More on reddit.com
🌐 r/javahelp
6
4
October 7, 2020
Do while loop skips the last step to get user input
nextEntry = in.nextLine(); should be nextEntry = in.next(); More on reddit.com
🌐 r/learnjava
8
5
December 18, 2021
Breaking from while loop when user enters nothing
if (nameEntered.equals("")) { or even better... if ("".equals(nameEntered)) { The == operator is generally not good for string comparisons because it tests if the two strings are the same object rather than testing the content of the strings. More on reddit.com
🌐 r/javahelp
11
2
March 13, 2018
🌐
Programiz
programiz.com › java-programming › do-while-loop
Java while and do...while Loop
In the above program, we have used the Scanner class to take input from the user. Here, nextInt() takes integer input from the user. The while loop continues until the user enters a negative number.
🌐
Delft Stack
delftstack.com › home › howto › java › java do while loop with user input
How to Create Java Do-While Loop With User Input | Delft Stack
February 2, 2024 - In this code, the do part is used to display the menu and take input from the user, while the conditional part depends on the user input.
🌐
W3Schools
w3schools.com › java › java_while_loop_do.asp
Java Do/While Loop
Summary: A do/while loop always runs at least once, even if the condition is false at the start. This is the key difference from a while loop, which would skip the code block completely in the same situation. This behavior makes do/while useful when you want something to happen at least once, such as showing a message or asking the user for input.
Find elsewhere
🌐
Programming Simplified
programmingsimplified.com › java › tutorial › java-while-loop
Java while loop | Programming Simplified
September 6, 2025 - We test a user input and if it's zero then we use "break" to exit or come out of the loop. ... class BreakWhileLoop { public static void main(String[] args) { int n; Scanner input = new Scanner(System.in); while (true) { // Condition in while loop is always true here System.out.println("Input ...
🌐
Coderanch
coderanch.com › t › 691813 › java › Loop-program-user-input
While-Loop for ending program from user input (Beginning Java forum at Coderanch)
March 17, 2018 - One often used approach where user input is required is to put the validation check and loop inside a method. Something like Then in the main body of your code you can call it like: And remove all your validation from your main body. Much cleaner. JavaRanch-FAQ HowToAskQuestionsOnJavaRanch ...
🌐
BeginwithJava
beginwithjava.com › java › loops › do-while-loop.html
Do While Loop in Java
The do while loop is similar to the while loop with an important difference: the do while loop performs a test after each execution of the loop body. import java.util.Scanner; // needed for Scanner Class /** * This program demonstrate do while loop. */ public class AddNumbers { public static void main(String[] args) { int value; // to hold data entered by the user int sum = 0; // initialize the sum char choice; // to hold 'y' or 'n' // Create a Scanner object for keyboard input...
🌐
W3Schools
w3schools.com › java › java_while_loop.asp
Java While Loop
In the next chapter, you will learn about the do while loop, which always runs the code at least once before checking the condition. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Linus Tech Tips
linustechtips.com › software › programming
How can I do a while loop with user input? (Java) - Programming - Linus Tech Tips
November 22, 2024 - I learned C++ before this, and that is why the loop is written that way Example: while (cin >> input) {...} I know that the way I'm trying to use the scanner doesn't work, because it requires the user to input twice, b...
🌐
YouTube
youtube.com › watch
Java Do While Loop Example Where User Prompts to Start Program Over - Appficial - YouTube
More videos coming soon, please SUBSCRIBE!A do-while loop is a post-test loop that executes its body of code at least once, and then repeats while the loop's...
Published   October 7, 2017
🌐
CodersLegacy
coderslegacy.com › home › learn java › java do while loop
Java do while loop - CodersLegacy
April 28, 2020 - The above code is designed to keep taking input from the user, adding them up in the variable sum until a negative number is input to terminate the loop. The use of the do while loop is important here as the code must run once so that the value of x can be obtained to be matched against the condition. This is contrast to the while loop, which would first check the condition and throw an error since x has no value at that point. If you don’t understand how we’re taking input here, see the Java input guide.
🌐
Sololearn
sololearn.com › en › Discuss › 2878470 › safety-first-java-do-while-loop-challenge
Safety first - java do while loop challenge | Sololearn: Learn to code for FREE!
January 4, 2018 - Below is the code that i have written ... System.out.println("Write password"); password ++; }while(password < 3); } } ... - First start the do loop....
🌐
SitePoint
sitepoint.com › blog › java › java’s while and do-while loops in five minutes
Java's While and Do-While Loops in Five Minutes — SitePoint
November 5, 2024 - Without a condition, the loop would become an infinite loop, which is generally undesirable. You can use a while loop to read user input until a valid input is received by placing the user input statement inside the loop.
🌐
Engineering LibreTexts
eng.libretexts.org › bookshelves › computer science › programming languages › think java - how to think like a computer scientist (downey) › 15: loops
15.6: The do-while Loop - Engineering LibreTexts
December 1, 2020 - We can use a do-while loop to keep ... in.nextDouble(); Although this code looks complicated, it is essentially only three steps: Display a prompt....
🌐
Coderanch
coderanch.com › t › 684625 › java › loop-user-input
While loop and user input (Beginning Java forum at Coderanch)
September 12, 2017 - Carey Brown wrote:You'll want to replace your a-- with edd.nextInt(). Every time through the loop you'll want to get another int. Also, variable names should begin with a lower case character, so it should be edd and not Edd. Alright but if i want to now use a text and number, and I want to print the text much as the number specifies, how do I do that? using While Thanks for your help! Hope you dont mind these noob questions. ... Mixing input as a number and as text potentially exposes you to one of the Scanner's gotchas.
🌐
Delft Stack
delftstack.com › home › howto › java › java while loop user input
How to Implement Java while Loop With User Input | Delft Stack
April 9, 2024 - The while loop checks if the input is not equal to “exit”. Inside the loop, we prompt the user to enter something and read their input using scanner.nextLine(). The loop continues until the user types “exit”, effectively allowing the ...
🌐
Reddit
reddit.com › r/javahelp › pausing a while loop to get user input, help
r/javahelp on Reddit: Pausing a while loop to get user input, help
October 7, 2020 -

Hello reddit! Here is my code for my assignment for my compsci class in college. I am a beginner but have the task of making a user-input binary string that updates after every user input. I have nested the program in a while loop so it reprompts the user every time to get a new input for the user. However, it infinitely uses the user's first input each time, with no way to pause the loop to wait for the user's input again. Is there a fix for this? Any help is greatly appreciated. Thank you all for your time! :)

import java.util.Scanner;

public class Program05a {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner stdIn = new Scanner (System.in);
	
	String bitString = "";
	int resultSoFar = 0;
	int userInput = 3;
	while (userInput != 2)
	{
		System.out.println("0 -> Shift Left, Add 0");
		System.out.println("0 -> Shift Left, Add 1");
		System.out.println("2 -> Exit, Evaluate");
		while ((userInput != 1) && (userInput != 2) && (userInput != 0))
		{
			System.out.print("Choose an operator from the menu above : ");
			userInput = stdIn.nextInt();
		}
		if (userInput != 2)
		{
			if (userInput == 0)
			{
				bitString = bitString + "0";
				System.out.println(bitString);
				resultSoFar = 2*resultSoFar + 0;
			}
			else if (userInput == 1)
			{
				bitString = bitString + "1";
				System.out.println(bitString);
				resultSoFar = 2*resultSoFar + 1;
			}
			
		}
	}
	System.out.println("\nThe value of the bit is: " + resultSoFar);
	
	stdIn.close();

}

}

Top answer
1 of 2
1

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2 of 2
1

Step through your code line by line (manually don't actually run it) and see how userInput changes as you loop though the program.

Especially look at this line:

userInput = stdIn.nextInt();

As it's the only line that changes the value of userInput.

Example:

for(int i = 0; i < 4; i++) {
    // i == 0, 1, 2, 3
    if(i % 2 == 0) { // true for 0 and 2
        print(i); // prints 02
    }
}