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 9229349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:32:57+00:00 2026-06-18T05:32:57+00:00

So, I have a loop that uses the Scanner to input 3 separate pieces

  • 0

So, I have a loop that uses the Scanner to input 3 separate pieces of user input, 2 ints and a String. The ints work just fine, but the String input is not working. It skips over the iput for the String, and just loops around to ask for the int again.

for(int e = 10; e > 5; e++)
    {
        System.out.println("Enter the Y coordinate of your guess. The upper left corner is 0, and the lower left is 7");
        int guessY = inputDevice.nextInt();
        System.out.println("Enter the X coordinate of your guess. The upper left corner is 0, and the upper right is 7");
        int guessX = inputDevice.nextInt();

        display[guessX][guessY] = map[guessX][guessY];
        for(int j = 0; j < 8; j++)

                {

            for(int t = 0; t < 8; t++)

            {

                System.out.print(display[j][t] + " ");

            }

            System.out.println();

        }


        System.out.println("Enter go when you are ready to make another move.");
        System.out.println("Enter quit to give up");
        String cont = inputDevice.nextLine();

        if(cont.equalsIgnoreCase("quit"))
        {
            System.out.println("Weenie.");
            System.exit(0);
        } else if(cont.equalsIgnoreCase("go")) {
            for(int i = 0; i < 100; i++)
                System.out.println("\b");
        }

        if(map[guessX][guessY] == '0')
        {
            if(map[guessX - 1][guessY - 1] == '0')
                display[guessX - 1][guessY - 1] = map[guessX - 1][guessY - 1];
            if(map[guessX - 1][guessY + 0] == '0')
                display[guessX - 1][guessY + 0] = map[guessX - 1][guessY + 0];
            if(map[guessX - 1][guessY + 1] == '0')
                display[guessX - 1][guessY + 1] = map[guessX - 1][guessY + 1];
            if(map[guessX + 0][guessY - 1] == '0')
                display[guessX + 0][guessY - 1] = map[guessX + 0][guessY - 1];
            if(map[guessX + 0][guessY + 1] == '0')
                display[guessX + 0][guessY + 1] = map[guessX + 0][guessY + 1];
            if(map[guessX + 1][guessY - 1] == '0')
                display[guessX + 1][guessY - 1] = map[guessX + 1][guessY - 1];
            if(map[guessX + 1][guessY + 0] == '0')
                display[guessX + 1][guessY + 0] = map[guessX + 1][guessY + 0];
            if(map[guessX + 1][guessY + 1] == '0')
                display[guessX + 1][guessY + 1] = map[guessX + 1][guessY + 1];
        }
        if(display[guessX][guessY] == 'M')
        {
            System.out.println("You hit a mine");
            System.out.println("Game over.");
            System.exit(0);
        }
    }
  • 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-18T05:32:58+00:00Added an answer on June 18, 2026 at 5:32 am

    From java 7 documentation http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html :

    public String nextLine()
    Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end. The position is set to the beginning of the next line.

    Since this method continues to search through the input looking for a line separator, it may buffer all of the input searching for the line to skip if no line separators are present.

    You probably wanted to use:

    public String next()
    Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern. This method may block while waiting for input to scan, even if a previous invocation of hasNext() returned true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a while loop that uses stringstream/getline() to parse a string, however I'm
On my homepage I have a loop of posts that uses infinite scroll. A
I have a script that uses a simple while loop to display a progress
I have a loop that works but not when I try and use it
I have a loop that takes values from textboxes and dropdowns and uses them
I have the following code that uses a for loop and I would like
I have a written a script that uses different modules. The script a loop,
How can I make a loop that can take user input every time it
I have a partial template that uses a User object as a model. The
I have a loop that uses the foreach keyword: foreach ($ln in Get-Content c:\ATextFile.txt

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.