troubleshooting Question

Java quiz program

Avatar of Mick 3009
Mick 3009 asked on
3 Comments1 Solution626 ViewsLast Modified:
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();
        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();
        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!");}
Jeffrey Dake
Senior Director of Technology

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros