I am making a basic quiz show in Java and I have successfully made the first question. Now when I went ahead and made my second question I encountered this problem. When I run the program there are no errors with it, but it will not let me input a response for the second question and instead just uses my answer for the first question. Please let me know what I can do to fix this.

import java.awt.*;
import java.applet.*;
import java.io.*;

public class Quiz_Show extends Applet
{
    public static void main (String args[])
    {
        InputStreamReader istream = new InputStreamReader (System.in);
        BufferedReader bufRead = new BufferedReader (istream);
        String Answer = "";
        int score = 0;
        System.out.println ("Welcome to my quiz show.");
        System.out.println ("Please enter the letter of the answer for each question and press enter.");
        System.out.println ("Here is the first question.");
        System.out.println ("What is the largest country in the world?");
        System.out.println ("A-Canada");
        System.out.println ("B-Russia");
        System.out.println ("C-USA");
        System.out.println ("D-China");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("b"))
        {
            System.out.println ("Good job, that is correct!");
            score = score + 15;
        }
        else
        {
            System.out.println ("Sorry, that answer is incorrect.");
            score = score - 5;
        }
        System.out.println ("Time for question two.");
        System.out.println ("What is 32+(4x9)?");
        System.out.println ("A-32");
        System.out.println ("B-324");
        System.out.println ("C-36");
        System.out.println ("D-68");
        while (Answer.equalsIgnoreCase (""))
        {
            try
            {
                System.out.println ("Please answer with a, b, c, or d");
                Answer = bufRead.readLine ();
            }
            catch (IOException err)
            {
                System.out.println ("Error reading line");
            }
        }
        if (Answer.equals ("d"))
        {
            System.out.println ("Nice work, that's right!");
            score = score + 15;
        }
        else
        {
            System.out.println ("Sorry, that's not the right answer.");
            score = score - 5;
        }
    }
}

Also if you could please let me know how I would get the program to tell the user what their current score is.

Dani AI

Generated

Quick diagnosis for : the second input loop is skipped because the same Answer variable still holds the first reply. is right that clearing the variable before the next question will make the loop run, but a cleaner, more reliable approach is to read each question into a fresh local variable or encapsulate the prompt/validation in a helper method. Also normalize input (trim and lowercase) or use case-insensitive comparison so B and b are treated the same.

The root cause: the second while checks whether the input variable is empty. Since it already contains the first answer, the loop never executes and the old value is reused. Two safe fixes: reset the variable to an empty string before asking the next question, or refactor so each question calls a method that reads and validates its own input and returns the score delta. Always print the updated score after adjusting it.

Example pattern (uses Scanner, a per-question helper, and prints the current score):

import java.util.Scanner;

public class Quiz {
  static int ask(Scanner sc, String q, String[] opts, char correct) {
    while (true) {
      System.out.println(q);
      for (String o : opts) System.out.println(o);
      System.out.print("Answer (a-d): ");
      String line = sc.nextLine();
      if (line == null) return 0;
      line = line.trim().toLowerCase();
      if (line.isEmpty()) continue;
      char c = line.charAt(0);
      if (c < 'a' || c > 'd') { System.out.println("Enter a, b, c, or d."); continue; }
      return (c == Character.toLowerCase(correct)) ? 15 : -5;
    }
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int score = 0;
    score += ask(sc, "Question 1 text", new String[]{"A) ...","B) ...","C) ...","D) ..."}, 'b');
    System.out.println("Current score: " + score);
    score += ask(sc, "Question 2 text", new String[]{"A) ...","B) ...","C) ...","D) ..."}, 'd');
    System.out.println("Final score: " + score);
    sc.close();
  }
}

Note: the posted class extends Applet but uses console I/O and main; either remove extends Applet for a console program or convert the logic into GUI/applet methods, since an applet does not provide a console.

Hi
You should reset the Answer variable to empty

Answer="";

;
before the second question to enter the next while loop.
Hope it helps

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.