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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:25:30+00:00 2026-05-27T10:25:30+00:00

In part of my java program I read a sequence of inputs for the

  • 0

In part of my java program I read a sequence of inputs for the user.

Scanner in = new Scanner(System.in);
System.out.println();
System.out.print("Enter student name: ");
String nameParameter = in.nextLine();
System.out.print("Enter student number: ");
int studentNoParameter = in.nextInt();
System.out.print("Enter subject: ");
String subjectParameter = in.nextLine();
System.out.print("Enter level: ");
int levelParameter = in.nextInt();
int[] resultsParameter;
resultsParameter = new int[3];
System.out.println("Enter results (0 if not taken yet)...");
System.out.print("First year: ");
resultsParameter[0] = in.nextInt();
System.out.print("Second year: ");
resultsParameter[1] = in.nextInt();
System.out.print("Third year: ");
resultsParameter[2] = in.nextInt();
System.out.println();

The program compiles, however the line:

String subjectParameter = in.nextLine();

after the prompt to enter Subject, is seemingly skipped in runtime.

Instead of my output being:

Enter Subject: [User Input]

Enter Level: [User Input]

It comes out as:

Enter Subject: Enter Level: [User Input]

The following input is assigned to levelParameter, and an error results if you input something other than an integer, so it seems that the line of code has simply been skipped.

I’m very much a java novice and I’m rather confused. I know this is going to turn out to be something really simple and silly in the end though. Thank you in advance for your time.

  • 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-27T10:25:31+00:00Added an answer on May 27, 2026 at 10:25 am

    That’s because after reading the int, the rest of the line (which is empty) is still unread and the next call to read nextline() will read the empty line.

    So when

    int studentNoParameter = in.nextInt(); 
    

    is executed, you enter the int and you hit enter, which creates a ‘\n’ as input.
    The next call:

    in.nextLine(); 
    

    continues to read the rest of the line after the int, which is empty, and it encounters ‘\n’ and terminates.

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

Sidebar

Related Questions

I'm trying to migrate an existing actionscript program (server part) to java (red5). However,
I've been asked (as part of homework) to design a Java program that does
I'm creating a windows service program which invokes a java program. Here is part
/* * * Hangman.java * The program asks the user to choose a file
Here is a part from my program: try { Class.forName(com.mysql.jdbc.Driver); InitializeData data = new
I have written provider part in java. Notification is sent to the APNs. Not
For years and years, I've tried to understand the part of Java specification that
Part of our java application needs to run javascript that is written by non-developers.
Reading Java Concurrency In Practice, there's this part in section 3.5: public Holder holder;
I'm part of a team that develops a pretty big Swing Java Applet. Most

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.