Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8646295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:46:15+00:00 2026-06-12T12:46:15+00:00

Scanner scanner = new Scanner(system.in); String input = new String(); while(!input.equalsIgnoreCase(stop)) { input =

  • 0
Scanner scanner = new Scanner(system.in);
String input = new String();

while(!input.equalsIgnoreCase("stop")) {
input = scanner.nextLine();
}

Why is this not working? The loop lasts forever. I have used this method a million times before and now it wont work.

EDIT**

Okay I am using JGrasp (as this is what my professor wants us to use)
and when I tried this in netbeans it worked fine…

EDIT2**

First of all I am not sure whether or not this is the problem but in my code I had something like this towards the beginning of main
Scanner scanner = new Scanner(file);
And later on something like this
scanner = new Scanner(System.in);
and that is where the previous code snippet starts off. So first of all I changed this by having main call a new method for the area where I needed the while loop with string checking. And I also reformatted the loop:

Scanner scanner = new Scanner(System.in);
    String input = new String();

    while(!input.contains("stop")) {
        System.out.print("Enter an option: ");
        input = scanner.nextLine();
    }

And now it works fine.

EDIT3**

So I tried the original format inside the new method and it also works perfectly. I believe now that it has something to do with how I had a scanner for the file and then reused that reference for a new scanner object with System.in. I am not 100% on that, but moving the while loop to a method of its own and not keeping it in main worked, so I feel like it has something to do with that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:46:16+00:00Added an answer on June 12, 2026 at 12:46 pm

    Perhaps you should be checking that the Scanner has something left to parse?

    while(scanner.hasNextLine() && !input.equalsIgnoreCase("stop")) {
        input = scanner.nextLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My main method: public static void main(String[] args) { Scanner input = new Scanner(System.in);
this code is correct?? String note = text.txt; FileWriter file = new FileWriter(note); Scanner
public void getWebContent() throws Exception { Scanner in = new Scanner(System.in); System.out.println(Input URL:); fileURL
System.out.println(Please enter the required word :); Scanner scan2 = new Scanner(System.in); String word2 =
If I have the following Java code: int[][] readAPuzzle() { Scanner input = new
Here's my code: public void readFile() throws IOException { System.out.println(Input file name: ); Scanner
I am trying to have a scanner take input in a loop. Once the
1) The first loop I need to use is a do/while. In this loop
This program is suppose to accept input into a string, the password. The program
Scanner s = null; try { s = new Scanner(new BufferedReader(new FileReader(rates.txt))); for (int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.