0

I'm trying to figure out how to pull from a list of questions and then output them using JTextArea. Right now I'm stuck trying to figure out how to randomly select from the list and then output it. This is what i have so far.

public static void Question()
  {
    String[] quest = {"place", "hold", "er"};
    int[] questNum = {1, 2, 3};


    JTextArea question = new JTextArea(6, 20);
    question.setText("Question " + questNum + quest);
  }
  • Possible duplicate of [How to randomly pick an element from an array](https://stackoverflow.com/questions/8065532/how-to-randomly-pick-an-element-from-an-array) – JDC Jul 17 '17 at 05:36
  • Why not do away with `questNum` and simply use `quest`'s index plus 1 wherever you need that? – Tim M. Jul 18 '17 at 15:00

1 Answers1

0

iterating array's and display in JTextArea

public static void Question()
  {
    String[] quest = {"place", "hold", "er"};
    int[] questNum = {1, 2, 3};

    String textContent = new String();
    for (int i = 0; i < quest.length; i++) {
     textContent += quest[i] + " ";
    }

    for (int i = 0; i < questNum.length; i++) {
     textContent += questNum[i] + " ";
    }

    JTextArea question = new JTextArea(6, 20);
    question.setText("Question " + textContent);
  }
Chirag Goti
  • 116
  • 1