import java.io.*;
public class QuizBee
{
    public static void main(String[] args)throws IOException
    {
        BufferedReader a = new BufferedReader(new InputStreamReader(System.in));
        int cor=0;

        System.out.println("\t \t \t \t \t \t \tWelcome to 10th Annual Quiz Bee of the Year");
        System.out.println();
        System.out.println("General Direction: In this question you are obligue to answer them honestly.");
        System.out.println("\t \t \t \t \tThis set's of question comes from many topics.");
        System.out.println();
        System.out.print("Please Enter Your Name For Identification: ");
        String name = a.readLine();
        System.out.println();
        System.out.println("Hello " + name);
        System.out.println();
        System.out.print("\"Press [Y\\y] if you wish to proceed to the questions and [N\\n] if you don\'t.\" ");
        String proceed = a.readLine();
        System.out.println();
        if (proceed.equalsIgnoreCase("y"))
        {
            System.out.println("1. What is the exponential form of 8 x 1 000 000 000?");
            System.out.println("\t \t \ta. 8 x 10^7");
            System.out.println("\t \t \tb. 8 x 10^8");
            System.out.println("\t \t \tc. 8 x 10^9");
            System.out.println("\t \t \td. 8 x 10^10");
            System.out.print("\t \t \tEnter you answer: ");
            String ans1 = a.readLine();
            if(ans1.equalsIgnoreCase("c"))
            {
                cor+=1;
            }
            System.out.println("2. Which of the following makes the muscle less flexible?");
            System.out.println("\t \t \ta. Bone tissue");
            System.out.println("\t \t \tb. Muscle tissue");
            System.out.println("\t \t \tc. Connective tissue");
            System.out.println("\t \t \td. Tissue paper");
            System.out.print("\t \t \tEnter you answer: ");
            String ans2 = a.readLine();
            if(ans2.equalsIgnoreCase("b"))
            {
                cor+=1;
            }
            System.out.println("3. The person who lost fingers but still can play guitar?");
            System.out.println("\t \t \ta. Ray Charles");
            System.out.println("\t \t \tb. Steve Wonder");
            System.out.println("\t \t \tc. Tony Iommi");
            System.out.println("\t \t \td. Michael Jackson");
            System.out.print("\t \t \tEnter you answer: ");
            String ans3 = a.readLine();
            if(ans3.equalsIgnoreCase("c"))
            {
                cor+=1;
            }
            System.out.println("4. What is the Immense body of water?");
            System.out.println("\t \t \ta. Sea");
            System.out.println("\t \t \tb. Waterfalls");
            System.out.println("\t \t \tc. River");
            System.out.println("\t \t \td. Ocean");
            System.out.print("\t \t \tEnter you answer: ");
            String ans4 = a.readLine();
            if(ans4.equalsIgnoreCase("d"))
            {
                cor+=1;
            }
            System.out.println("5. What body of water may not flow and have specific destination?");
            System.out.println("\t \t \ta. Sea");
            System.out.println("\t \t \tb. Waterfalls");
            System.out.println("\t \t \tc. River");
            System.out.println("\t \t \td. Ocean");
            System.out.print("\t \t \tEnter you answer: ");
            String ans5 = a.readLine();
            if(ans5.equalsIgnoreCase("c"))
            {
                cor+=1;
            }
            System.out.println("6. What form water does the ship dock?");
            System.out.println("\t \t \ta. Sea");
            System.out.println("\t \t \tb. Waterfalls");
            System.out.println("\t \t \tc. River");
            System.out.println("\t \t \td. Ocean");
            System.out.print("\t \t \tEnter you answer: ");
            String ans6 = a.readLine();
            if(ans6.equalsIgnoreCase("a"))
            {
                cor+=1;
            }
            System.out.println("7. Who is the Father of Geometry?");
            System.out.println("\t \t \ta. Euclid");
            System.out.println("\t \t \tb. Einstein");
            System.out.println("\t \t \tc. Turing");
            System.out.println("\t \t \td. " + name);
            System.out.print("\t \t \tEnter you answer: ");
            String ans7 = a.readLine();
            if(ans7.equalsIgnoreCase("a"))
            {
                cor+=1;
            }
            System.out.println("8. How many entrpreneurs set up the STI?");
            System.out.println("\t \t \ta. 3");
            System.out.println("\t \t \tb. 4");
            System.out.println("\t \t \tc. 5");
            System.out.println("\t \t \td. 6");
            System.out.print("\t \t \tEnter you answer: ");
            String ans8 = a.readLine();
            if(ans8.equalsIgnoreCase("b"))
            {
                cor+=1;
            }
            System.out.println("9. How many kind of mammals are there in a rainforest?");
            System.out.println("\t \t \ta. 125");
            System.out.println("\t \t \tb. 400");
            System.out.println("\t \t \tc. 100");
            System.out.println("\t \t \td. 65");
            System.out.print("\t \t \tEnter you answer: ");
            String ans9 = a.readLine();
            if(ans9.equalsIgnoreCase("a"))
            {
                cor+=1;
            }
            System.out.println("10. How many amphibians are there in a rainforest?");
            System.out.println("\t \t \ta. 125");
            System.out.println("\t \t \tb. 400");
            System.out.println("\t \t \tc. 100");
            System.out.println("\t \t \td. 65");
            System.out.print("\t \t \tEnter you answer: ");
            String ans10 = a.readLine();
            if(ans10.equalsIgnoreCase("d"))
            {
                cor+=1;
            }
            System.out.println();
            System.out.println("\t \t \tQuiz Result:");
            if(cor<5)
            {
            System.out.println("\t \t \tSorry " + name + " You Failed!");
            }
            else if (cor>5)
            System.out.println("\t \t \t" + name + " You Passed!");
            System.out.println("\t \t \tYou got " + cor + " correct answers");
            System.out.println("\t \t \tYou got " + (cor/10*50+50) + "%");
            System.out.print("\t \t \t\"Do you wish to try again? [Y\\N]\" ");
            String proceed1 = a.readLine();
            if(proceed1.equalsIgnoreCase("n"))
            {
                System.out.println("Goodbye " + name + ". Hope you enjoy the Quiz Bee of the Year!")
                System.exit(0);
            }
            System.out.println();

        }
        System.exit(0);
    }
}

how do i go back in question number 1 in this java code?..

Recommended Answers

All 4 Replies

Use a switch statement on a variable representing the question you are at. Then, to return to a specific question, you can reset the variable to that question, putting all of this in a loop.

how do i do that?.. sorry but i'm just learning it.. :))

Enclose the code you want to repeat in a loop like a while() loop.

  while(someCondition) {
     <  current code here >
  }  // end while()

To exit the loop: Change someCondition to false or use the break statement.

it's ok now.. this problem is solved.. btw thanks for those who answer me..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.