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

  • Home
  • SEARCH
  • 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 8475651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:57:01+00:00 2026-06-10T17:57:01+00:00

Im trying to create a quiz so that it asks you a question of

  • 0

Im trying to create a quiz so that it asks you a question of a multiple choice, though i cant seem to figure out on how to loop it back to the incorrect question..
Im still kind of new to java programming and my understanding is unfortunately not so good..

Here is what ive currently coded,

import java.util.*;
import java.util.Scanner;
import javax.swing.JOptionPane;

public class Quiz2
{
public static int question;
public static int question2;
public static int question3;
public static int question4;
public static int question5;

public static String guess;
public static String guess2;
public static String guess3;
public static String guess4;
public static String guess5;

public static void main(String[] args)
{   
    //create a scanner object
    Scanner sc = new Scanner(System.in);

    JOptionPane.showMessageDialog(null, "Hi, This is my Quiz\nYou will be asked a total of 5 questions in multiple choice format\nPlease answer as A/B/C/D (Not case sensative)", "Introduction",
    JOptionPane.INFORMATION_MESSAGE);

    //Asks for a paricular item from the keyboard
    guess  = JOptionPane.showInputDialog(null, "1. Which of the following is not a bright colour?\nA. Cyan\nB. Green\nC. Black\nD. Yellow\nAnswer: ", "Question 1",
    JOptionPane.INFORMATION_MESSAGE);

    //Asks for a paricular item from the keyboard
    guess2  = JOptionPane.showInputDialog(null, "2. What genre does the singer John Legend sing in?\nA. Pop\nB. R&b\nC. Rap\nD. Rock\nAnswer: ", "Question 2",
    JOptionPane.INFORMATION_MESSAGE);

    //Asks for a paricular item from the keyboard
    guess3  = JOptionPane.showInputDialog(null, "3. What is the largest discovered Star in the Universe?\nA. The Sun\nB. VY Canis Majoris\nC. Eta Carinae\nD. Beetlejuice\nAnswer: ", "Question 2",
    JOptionPane.INFORMATION_MESSAGE);

    //Asks for a paricular item from the keyboard
    guess4  = JOptionPane.showInputDialog(null, "4. Who is Ronaldinho Gaucho?\nA. A famous Soccer player\nB. A famous Singer\nC. The founder of Microsoft\nD. A famous Actor\nAnswer: ", "Question 2",
    JOptionPane.INFORMATION_MESSAGE);

    //Asks for a paricular item from the keyboard
    guess5  = JOptionPane.showInputDialog(null, "5. Who is the actor who played the role as the terminator in the movie Last Action Hero?\nA. Arnold Schwarzenegger\nB. Adam Sandler\nC. Jean Claude Van Damme\nD. Sylvester Stallone\nAnswer: ", "Question 2",
    JOptionPane.INFORMATION_MESSAGE);

    char x1 = guess.charAt(0);
    char x2 = guess2.charAt(0);
    char x3 = guess3.charAt(0);
    char x4 = guess4.charAt(0);
    char x5 = guess5.charAt(0);

    switch (x1)
    {
        case 'a': 
        case 'A':
                    JOptionPane.showMessageDialog(null, "Incorrect! Cyan is a bright colour, Please Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'b':
        case 'B':
                    JOptionPane.showMessageDialog(null, "Incorrect! Green is a bright colour, Please Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'c': 
        case 'C':
                    JOptionPane.showMessageDialog(null, "Correct! Black is not a bright colour", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'd':
        case 'D': 
                    JOptionPane.showMessageDialog(null, "Incorrect! Yellow is a bright colour, Please Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
    }



    switch (x2)
    {
        case 'a': 
        case 'A':
                    JOptionPane.showMessageDialog(null, "Incorrect! John Legend is not a Pop Singer!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'b':
        case 'B':
                    JOptionPane.showMessageDialog(null, "Correct! John Legend is a R&B Singer!", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'c': 
        case 'C':
                    JOptionPane.showMessageDialog(null, "Incorrect! John Legend does not Rap!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'd':
        case 'D': 
                    JOptionPane.showMessageDialog(null, "Incorrect! John Legend is not in the genre of Rock!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
    }

    switch (x3)
    {
        case 'a': 
        case 'A':
                    JOptionPane.showMessageDialog(null, "Incorrect! The Sun is the Biggest Star in our Solar System and not the Universe!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'b':
        case 'B':
                    JOptionPane.showMessageDialog(null, "Correct! VY Canis Majoris is currently the Largest Star Discovered in the Universe!", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'c': 
        case 'C':
                    JOptionPane.showMessageDialog(null, "Incorrect! Eta Carinae is the Second Largest Star Discovered in the Universe!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'd':
        case 'D': 
                    JOptionPane.showMessageDialog(null, "Incorrect! Beetlejuice is the Third Largest Star Discovered in the Universe!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
    }

    switch (x4)
    {
        case 'a': 
        case 'A':
                    JOptionPane.showMessageDialog(null, "Correct! Ronaldinho Gaucho is a famous Soccer player!", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'b':
        case 'B':
                    JOptionPane.showMessageDialog(null, "Incorrect! Ronaldinho Gaucho is not a Singer!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'c': 
        case 'C':
                    JOptionPane.showMessageDialog(null, "Incorrect! Bill Gates was the founder of Microsoft! NOT Ronaldinho Gaucho!!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'd':
        case 'D': 
                    JOptionPane.showMessageDialog(null, "Incorrect! Ronaldinho Gaucho is not an actor!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
    }

    switch (x5)
    {
        case 'a': 
        case 'A':
                    JOptionPane.showMessageDialog(null, "Incorrect! Arnold Schwarzenegger was the main actor of Last Action Hero, but in that same movie, who played the role as the terminator?\n Try Again!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'b':
        case 'B':
                    JOptionPane.showMessageDialog(null, "Incorrect! No its not Adam Sandler, but it would be funny if it was!,\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'c': 
        case 'C':
                    JOptionPane.showMessageDialog(null, "Incorrect! It could have been Jean Claude Van Damme!\nBut its not....\nPlease Try Again..", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
        case 'd':
        case 'D': 
                    JOptionPane.showMessageDialog(null, "Correct! Sylvester Stallone played the role as the Terminator in the Movie Last Action Hero!", "Answer CHECK!",
                    JOptionPane.INFORMATION_MESSAGE);
                    break;
    }
}
}

Now, Using this code..
How do i create a loop for the incorrect answer?
Help would be greatly appreciated, 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-06-10T17:57:03+00:00Added an answer on June 10, 2026 at 5:57 pm

    Your approach is only really going to work for a very simple example and you’re obviously having problems reacting to the user because you’re not keeping track of state.

    I wrote this up that does what you want (I think). Look through it and let me know if you have questions about how/why things are.

    https://gist.github.com/3579413

    (I put it on a public gist because there’s a lot of code…) Ideally you’d split those classes out into their own files so you don’t end up with a massively cumbersome file. Hopefully you get the idea.

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

Sidebar

Related Questions

I'm trying to figure out a way to create random numbers that feel random
I'm trying to create a random multiple choice quiz for android. I want to
So I'm trying to setup a multiple choice quiz via Python. I'm fairly new
I am a newbie, and trying to create a multiple-option quiz. I've created the
I am trying to create an Online Quiz script like expert rating test on
I'm trying to create a math quiz and I only want the user to
I'm trying to create a join query. I am busy with a quiz site
I am trying create a small web application that allows a user to login
I am trying to create a script for quiz. I have stored current timestamp
I'm trying to create a simple Quiz app (I'm a beginner), when I launch

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.