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

  • SEARCH
  • Home
  • 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 6849729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:01:46+00:00 2026-05-27T01:01:46+00:00

My code seems to repeat the for loop twice, before giving me the opportunity

  • 0

My code seems to repeat the for loop twice, before giving me the opportunity to answer. I’ve been staring at this all day, and I’m pretty sure I’m blind to whatever error I’ve made. Some help would be much appreciated.

I’m sorry for the Norwegian stuck in there, but it’s not relevant to the problem.

public static void verb(){
    System.out.print("Oppgi navn på verbfil: ");
    Scanner input = new Scanner(System.in);
    String fileName = input.nextLine();
    File textFile = new File(fileName);
    try{
        Scanner fileInput = new Scanner(textFile);
        System.out.print("\nVelkommen til programmet som tester deg i bøyning av engelske verb.\nDu kan velge opp til 88 verb å bli testet i.\nDu vil få en vurdering når testen er ferdig\n\n");
        System.out.print("Ønsker du å prøve dette? (ja/nei) ");
        String yesNo = input.next();
        if (yesNo.toLowerCase().equals("ja")){
            System.out.print("\nOppgi ønsket antall verb: ");
            int points = 0;
            int amountVerbs = input.nextInt();
            for (int i = 1; i <= amountVerbs; i++){
                String verb1 = fileInput.next();
                String verb2 = fileInput.next();
                String verb3 = fileInput.next();
                int verbSelect = randomGen(3);
                if (verbSelect == 1){
                    System.out.print("... " + verb2 + " - " + verb3);
                    System.out.print("\nSkriv inn formen som mangler: ");
                    String answer = input.nextLine();
                    if (answer.toLowerCase().equals(verb1)){
                        points+= 1;
                    }
                }
                if(verbSelect == 2){
                    System.out.print(verb1 + " - " + "..." + " - " + verb3);
                    System.out.print("\nSkriv inn formen som mangler: ");
                    String answer = input.nextLine();
                    if (answer.toLowerCase().equals(verb2)){
                        points+= 1;
                    }
                }
                if(verbSelect == 3){
                    System.out.print(verb1 + " - " + verb2 + " - " + "...");
                    System.out.print("\nSkriv inn formen som mangler: ");
                    String answer = input.nextLine();
                    if (answer.toLowerCase().equals(verb3)){
                        points+= 1;
                    }
                }
            }
            System.out.print("Oppgi navnet ditt: ");
            String name = input.nextLine();
            System.out.print(name + "\n" + "Score: " + points + " av " + amountVerbs);
        } else{
            System.out.print("Greit det.");
        }
    } catch (FileNotFoundException exc) {
        System.out.println("Feil filnavn!");
    }
}

public static int randomGen(int randMax){
    Random generator = new Random();
    int verbSelect = generator.nextInt(randMax) + 1;
    return verbSelect;
}

}
  • 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-05-27T01:01:47+00:00Added an answer on May 27, 2026 at 1:01 am

    Your problem is likely from your use of the Scanner object and how it handles the End Of Line (EOL) token. Note that only Scanner#nextLine() handles this token while next(), nextInt(), nextDouble() and the like do not. Often if you have the users enter a number, it is worthwhile calling nextLine() immediately after getting the numeric input.

    e.g.,

    Scanner input = new Scanner(System.in);
    int myInt = input.nextInt();
    input.nextLine(); // added to swallow the EOL token
    

    Consider changing this:

    String yesNo = input.next();
    

    to this

    String yesNo = input.nextLine(); // handles EOL.
    

    and this:

    int amountVerbs = input.nextInt(); 
    

    to this:

    int amountVerbs = input.nextInt();
    input.nextLine(); // to swallow the EOL token.
    

    and so-forth for your other uses of Scanner.

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

Sidebar

Related Questions

I have absolutely no idea why this is happening but the following code seems
I have 2 questions on this My code always seems to hit a 401
It seems the code and the book have been relegated to the foundation of
Basically I have a code: $response = myFunction(); I need to repeat this call
The code seems not working. // $counter is an instance of Zend_Db_Table_Abstract $counter->update(array('hits' =>
The following code seems to be just too much, for getting a single count
The below code seems like it should work; however, the blob in the database
I notice that modern C and C++ code seems to use size_t instead of
Hey guys, the following snippet of jQuery code seems to work fine in Google
I have the following code that seems like it should set my insertParameter but

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.