Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to compare arrays using JOption Pane in java?

Using JOption pane how would i compare two arrays i have the answers to multiple choice question but want to compare them what the user inputs. I display a message a that the user inputs an answer then i will enter that into a new array . i then want to compare the arrays to figure out if they passed i am stuck

any help would be great thanks

1 Answer

Relevance
  • Chris
    Lv 7
    8 years ago
    Favorite Answer

    something like this

    int questions = 10;

    int[] answer = new int[questions];

    for (int i = 0; i < questions; i++)

    answer[i] = Integer.parseInt( JOptionPane.showInputDialog( "Please enter the answer to question #" + (i+1) + ":"));

    // compare arrays

    boolean all_correct = true;

    for (int i = 0; i < questions; i++)

    if (answer[i] != correct_answer[i]) all_correct = false;

    if (all_correct) ...

Still have questions? Get your answers by asking now.