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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:24:02+00:00 2026-06-12T21:24:02+00:00

Possible Duplicate: Scanner issue when using nextLine after nextInt Why is the empty sc.nextLine();

  • 0

Possible Duplicate:
Scanner issue when using nextLine after nextInt

Why is the empty sc.nextLine(); under the husband so necessary? it did not equal to anything, and surely the wife did not have that line… but the program won’t run without it. My book comments it as Skip over trailing newLine character. but I don’t see how there’s anything to skip!

public class FileTest {
    public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    System.out.print("For your blended family, \n enter the wife's name");
    String wife = sc.nextLine();
    System.out.print("Enter the number of her children:");
    int herkids = sc.nextInt();

    System.out.print("Enter the husband's name:");
    //sc.nextLine();  // Why is this line so necessary? 
    String husband = sc.nextLine();
    System.out.print("Enter the number of his children:");
    int hisKids = sc.nextInt();

    System.out.println(wife + " and " + husband + " have " + (herkids + hisKids) + " children.");

    }
}
  • 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-12T21:24:03+00:00Added an answer on June 12, 2026 at 9:24 pm

    Check this question,

    Scanner issue when using nextLine after nextXXX

    Look at the accepted answer,

    “The problem is with the input.nextInt() command it only reads the int value. So when you continue reading with input.nextLine() you receive the “\n” Enter key. So to skip this you have to add the input.nextLine(). Hope this should be clear now.”

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

Sidebar

Related Questions

Possible Duplicate: Scanner issue when using nextLine after nextInt I am creating a client
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: String is not equal to string? I'm new to java and I
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: Can’t create handler inside thread that has not called Looper.prepare() inside AsyncTask
Possible Duplicate: Realloc is not resizing array of pointers Can anyone tell me where
Possible Duplicate: How to convert text to unicode code point like \u0054\u0068\u0069\u0073 using php?
Possible Duplicate: How to use iPhone Camera as Bar Code Scanner? hi all How
Possible Duplicate: java arraylist to store userinput Hi using the code in java how

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.