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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:19:28+00:00 2026-06-03T07:19:28+00:00

Here is the skeleton of some basic code I am writing to make a

  • 0

Here is the skeleton of some basic code I am writing to make a simple game:

    Scanner in = new Scanner(System.in);

    String name;
    String playing;
    int age;

    do {

        System.out.println("Enter your name");
        name = in.nextLine();

        System.out.println("Enter your age");
        age = in.nextInt();

        System.out.println("Play again?");
        playing = in.nextLine();

    } while (true);

The code does not work as expected, for example, here is the expected functioning of the code:

Enter your name
John
Enter your age
20
Play again?
Yes
Enter your name
Bill
...

However, there is an issue with reading the Play again line, this is the actual output:

Enter your name
John
Enter your age
20
Play again?
Enter your name

As you can see “Enter your name” is being displayed again before “Play again?” is able to accept input. When debugging the playing variable is set to “”, so there is no input that I can see and I cannot figure out what is being consumed.
Any help would be appreciated, thanks!

  • 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-03T07:19:29+00:00Added an answer on June 3, 2026 at 7:19 am

    nextInt() doesn’t consume the end-of-line, even if the int is the only thing in there.

    Add another nextLine() after reading the int, and either discard its value completely, or check that it is empty if you want to prevent people from entering anything but an int.

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

Sidebar

Related Questions

Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
I am writing my first jQuery plugin. Here's the skeleton of the plugin: (function(
I am writing some code that takes a LINQ to SQL IQueryable<T> and adds
I need to incrementally time some C code on a 32-bit Linux system. I
Here is my code: package com.commonsware.android.skeleton; import android.app.Activity; import android.content.Context; import android.hardware.Camera; import android.hardware.Camera.*;
I am a C/C++ programmer, and I am currently playing with some Javascript code,
Here's a skeleton Makefile just to make it easier to describe the problem: all_tests
Here's the code in AlertTableView: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger index = 12345; NSLog(@AlertTableView:
I have a simple class that holds skeleton for a much larger, bulkier class.
Can't figure this one out. Done research, searched here, online, etc. Still a new

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.