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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:05:18+00:00 2026-06-05T15:05:18+00:00

My string description crashes the Console because of the spaces generated in normal sentence

  • 0

My string description crashes the Console because of the spaces generated in normal sentence structure. i am looking for some guidance in reference to why this happens and futhermore if i am going about this the wrong way how should i be approaching it.

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
    System.out.println("-/- Job ticket  -/-");
    Scanner MyScanner = new Scanner (System.in);

    String FirstName;
    String LastName;
    String Phone;
    String Address;
    String Description;
    int ticketNumber;
    int orderMonth ;
    int orderDay;
    int orderYear;
    int requestedDay;
    int requestedMonth;
    int requestedYear;

    System.out.println("First Name = ?");
    FirstName = MyScanner.next();
    System.out.println("Last Name = ?");
    LastName = MyScanner.next();
    System.out.println("Phone = ?");
    Phone = MyScanner.next();
    System.out.println("Address = ?");
    Address = MyScanner.next();
    System.out.println("Description = ?");
    Description = MyScanner.next();
    System.out.println("Ticket = ?");
    ticketNumber = MyScanner.nextInt();
    System.out.println("Order Date Month = ?");
    orderMonth = MyScanner.nextInt();
    System.out.println("Order Date Day");
    orderDay = MyScanner.nextInt();
    System.out.println("Order Date Year");
    orderYear = MyScanner.nextInt();
    System.out.println("Requested Date Month");
    requestedMonth = MyScanner.nextInt();
    System.out.println("Requested Date Day");
    requestedDay = MyScanner.nextInt();
    System.out.println("Requested Date Year");
    requestedYear = MyScanner.nextInt();

    System.out.println("=====================================================");
    System.out.print("Ticket :   ");
    System.out.println(ticketNumber);
    System.out.print("Customer:   ");
    System.out.print(FirstName);
    System.out.print(" ");
    System.out.println(LastName);
    System.out.print("Home Phone: ");
    System.out.println(Phone);
    System.out.print("Order Date: ");
    System.out.print(orderMonth);
    System.out.print('/');
    System.out.print(orderDay);
    System.out.print('/');
    System.out.println(orderYear);
    System.out.print("Requested Date:   ");
    System.out.print(requestedMonth);
    System.out.print('/');
    System.out.print(requestedDay);
    System.out.print('/');
    System.out.println(requestedYear);
    System.out.println("-----------------------------------------------------");
    System.out.println("Address");
    System.out.println(Address);
    System.out.println("-----------------------------------------------------");
    System.out.println("Description");
    System.out.println(Description);
    System.out.println("=====================================================");
    System.out.println();
   }
}
  • 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-05T15:05:21+00:00Added an answer on June 5, 2026 at 3:05 pm

    I see a problem in your code here.

    When you use Scanner.next(), Scanner looks for the next whitespace ” ” and returns you all the text before that whitespace.

    This is due to the concept of delimiters in the Scanner class and the default delimiter is a ‘whitespace or next line’ (You might want to read up on delimiters).

    How does the delimiter work for you?

    Eg: Your input is “Hello World\r\n”

    When you invoke Scanner.next(), Scanner will find the whitespace, and return you everything before that, so it will return “Hello”.
    When you invoke Scanner.next() again, Scanner will find the \r\n (next line) and return you everything before that, so it will return “World”.

    Scanner will only prompt for new user input when it has finished reading all the input.

    So for your code, what will happen is that:

    Address = MyScanner.next();
    System.out.println("Description = ?");
    Description = MyScanner.next();
    System.out.println("Ticket = ?");
    

    If my input for Address is “123 ABC Avenue”, Address will only get the input “123”, while Description will automatically pull the value “ABC” from the input which is not empty yet.

    Thus, you will observe that the program appears to “skip” the Description user prompt.

    You should use the Scanner.nextLine() method if you want to pull the entire user input out from the Scanner, instead of Scanner.next()

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

Sidebar

Related Questions

There is some type Record : type Day = Integer type Description = String
I have a column with some string description in it. for example: Bob davids
Following class structure is given: class Job { String description; Collection<JobHistory> history; } class
I'm reading dicom tags using openDicom.net like this: string tag = ; string description
I've created a simple Project model with four attributes: Project name:string description:text complete:boolean user_id:integer
private string _itemId; [Browsable(true), Description(Required identifier for the Item.)] public string ItemId { get
How can i get Image tag from html String. I am getting description like
I'm going crazy with this and would greatly appreciate some help. Imagine two tables
I have a simple model FilesModel for updating a string Description and the boolean
I have a question to the following procedure: script/generate scaffold product title:string description:text db:migrate

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.