Java quiz program

I am having problems with my  Java program Quiz Game (code below). I am trying to do a random multiple choice question quiz but it does not work the way I wish to. The program should output three random questions at a time but at run time it is stopping after the first one. Can someone please help me out?

import java.util.Random;

public class Sample3{
public static void main (String args[])
{
    Random quiz = new Random();
    int question;
   
    for(int counter=1; counter<=3;counter++){
        question = 1+quiz.nextInt(3);
   
    System.out.println ("Welcome to the Quiz Game!");
 
       System.out.println ("The instructions are: you will be given one type of topic,");
       System.out.println ("The topic will have 3 multiple choice questions");
       System.out.println ("If you get one wrong you start from the beginning.");
       System.out.println ("If you get them all right you will win");
     
if ((question==1)){
           System.out.println ("question: How many players are there in 1 football team?");
           System.out.println ("9");
           System.out.println ("10");
           System.out.println ("11");
           }
int ans1=Keyboard.readInt();
           if((ans1==11)){    
        System.out.println ("Correct");}
if ((question==2)){
        System.out.println ("Question : Which of these teams play in the Premier League?");
        System.out.println ("press 1 for Juventus");
        System.out.println ("press 2 for Chelsea");
        System.out.println ("press 3 for PSG");
        }
int ans2=Keyboard.readInt();
        if((ans2==2)){
        System.out.println ("Correct");}
if ((question==3)){  
        System.out.println ("Question 3: How do you score?");
        System.out.println ("press 1 if by kicking the ball into the net");
        System.out.println ("press 2 if by throwing the ball into the net");
        System.out.println ("press 3 if by kicking the ball outside the turf");
        }
  int ans3=Keyboard.readInt();
        if ((ans3==1)){
                System.out.println ("Correct!");}
}
}
}
Mick 3009Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey Dake Senior Director of TechnologyCommented:
When you do int Keyboard.readInt(); the program is going to stop and wait for the input to be inputted by the  keyboard before continuing with the program.  You will need to move that call around if you want it to not wait before the other questions are displayed.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
krakatoaCommented:
Using a random approach like that which is in a finite for loop is the opposite of a guarantee that all three questions will be asked - which seems strange to say the least.

You need something like a while loop instead, which runs until three questions have been answered. You'll then also have to ensure that 3 *different* questions were answered, otherwise nothing will make sense.
0
Mick 3009Author Commented:
Thank you for your comment. Program updated accordingly and problem solved!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.