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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:29:19+00:00 2026-06-09T16:29:19+00:00

import java.util.List; import ShortHand.utilities.CollectionCreation; public class MultipleChoice<Q,A,C> { Q question; A answer; C choices;

  • 0
import java.util.List;

import ShortHand.utilities.CollectionCreation;

public class MultipleChoice<Q,A,C>
{
    Q question;
    A answer;
    C choices;

    public MultipleChoice(Q q, A a, C c){
        question = q;
        answer = a;
        choices = c;
    }

    public Q getQuestion(){ return question;  }
    public A getAnswer(){ return answer;  }
    public C getChoices(){ return choices;  }

    public void addChoices(C c ){ choices = c; }
    public void addQuestion(Q q){ question = q; }
    public void addAnswer(A a){ answer = a; }

    public String toString(){
         return "Question: "+this.getQuestion()+ "\n"+
                "Choices: "+this.getChoices();
    }

    public static void main(String[] args){
        java.util.Scanner input = new java.util.Scanner(System.in);

        List<MultipleChoice<String,String,String>> mc = CollectionCreation.list();
        int numOfQuestions;
        System.out.print("Enter number of Question: ");
        numOfQuestions = input.nextInt();
        System.out.println();
        for(int i = 0; i< numOfQuestions; i++){
            System.out.println("Enter Question: ");
            String question = input.nextLine();
            System.out.println("Enter choices: ");
            String choices = input.nextLine();
            System.out.println("Enter Answer: ");
            String answer = input.nextLine();
            mc.add(new MultipleChoice(question,choices,answer));
        }

        for(MultipleChoice<String, String, String> items : mc)
            System.out.println(items+"\n");

    }
}

My problem here is that when the loop started I can’t seem to input in the The question itself under the “Enter your Question” and same goes for others. any idea why?

What I am expecting is that the once I click enter it would go to “Enter The choices”.

But it seems they’re printing at the same time therefore rendering me to unable to answer the “Enter your question” should I fix this?

CollectionCreation is just returning an arrayList() using type inference

  • 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-09T16:29:20+00:00Added an answer on June 9, 2026 at 4:29 pm

    Beacuse you’re reading from System.in, the Scanner won’t get any input until you hit enter. Thus when you read only an int using nextInt(), there’s an extra newline in the buffer that isn’t read, and it gets instantly read in the next input.nextLine() call (which will be an empty String.

    Try changing the nextInt() to nextLine():

    numOfQuestions = Integer.parseInt(input.nextLine().trim());
    

    Alternatively, you can reset() the scanner after the nextInt() call.

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

Sidebar

Related Questions

import java.util.Arrays; import java.util.ArrayList; import java.util.Scanner; import java.util.Collections; import java.util.List; public class TennisTournament {
I'm confused by the following code: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class
please have a look at the following code import java.util.ArrayList; import java.util.List; public class
Is this valid Java? import java.util.Arrays; import java.util.List; class TestWillThatCompile { public static String
When compiling this import java.util.List; public class Test { public static class Subject {
package de.tablayoutexample; import java.util.List; import android.os.AsyncTask; import android.util.Log; public class CallWebServiceTask extends AsyncTask<String, String,
import java.util.*; public class MyClass { public static void main(String[] args) { List<String> a
I have this code snippet import java.util.ArrayList; import java.util.List; public class AssertTest { public
Source Code of LoginAction.java package com.test; import java.util.ArrayList; import java.util.List; public class LoginAction {
Take the following generics example import java.util.List; import java.util.ArrayList; public class GenericsTest { private

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.