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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:19:45+00:00 2026-05-16T23:19:45+00:00

Alright, very noob question. I’m making a CLI app that lets users design surveys.

  • 0

Alright, very noob question. I’m making a CLI app that lets users design surveys. First they enter the question, then the number of choices and the choices. I’m using a Scanner to get input, and for some reason it lets the user enter most things, but not the text of the question. Code snippet below.

String title = "";
Question[] questions;
int noOfQuestions = 0;
int[] noOfChoices;
Scanner entry = new Scanner(System.in);
System.out.println("Please enter the title of the survey: ");
title = entry.nextLine();
System.out.println("Please enter the number of questions: ");
noOfQuestions = entry.nextInt();
noOfChoices = new int[noOfQuestions];
questions = new Question[noOfQuestions];
for (int i = 0; i < noOfQuestions; i++) {
    questions[i] = new Question();
}
for (int i = 0; i < noOfQuestions; i++) {

    System.out.println("Please enter the text of question " + (i + 1) + ": ");
    questions[i].questionContent = entry.nextLine();
    System.out.println("Please enter the number of choices for question " + (i + 1) + ": ");
    questions[i].choices = new String[entry.nextInt()];
    for (int j = 0; j < questions[i].choices.length; j++) {
        System.out.println("Please enter choice " + (j + 1) + " for question " + (i + 1) + ": ");
        questions[i].choices[j] = entry.nextLine(); 

    }
}

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-05-16T23:19:46+00:00Added an answer on May 16, 2026 at 11:19 pm

    The reason I asked about whether you read noOfQuestions from the Scanner is because Scanner.nextInt() does not consume the delimiter (e.g. the new line).

    That means that the next time you call nextLine(), you will just get an empty String from the previous readInt().

    75\nQuestion 1: What is the square route of pie?
    ^ position before nextInt()
    
    75\nQuestion 1: What is the square route of pie?
      ^ position after nextInt()
    
    75\nQuestion 1: What is the square route of pie?
        ^ position after nextLine()
    

    My suggestion is to just read by line, always with nextLine(), and then parse afterwards using Integer.parseInt().

    If that’s the route you take, there’s little need for a Scanner at all; you can just accept a BufferedReader.

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

Sidebar

Related Questions

Alright, here goes. I'm making a very basic app, and I want the user
Alright, this is a very simple question. I just installed Tomcat 6 on my
I am learning cakePHP, everything seems alright except that I am very confused of
Alright, so I know this is a large Procedure, but my question is very
Alright, I am very confused, so I hope you friends can help me out.
Alright so i need to open a .txt file that will be created in
Alright so this is a bizarre cross platform thing that I'm experiencing with text
Alright, I have some weird behavior and this question goes to the people out
Alright, I was tasked to develop a Windows Service that listens to a directory
Alright, so here's my problem. I'm trying to write a script in PHP that

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.