Ask coding questions

← Back to all posts
How do I fix this line to fit my arraylist program
h
xMisbahx (15)

I have an arraylist, and I have the line of code to make it random, but only for numbers. How do I make it so that it will accept sentences/words instead of numbers?
here is a portion code:

if (yesno.equals("yes")) {
System.out.println("Simon Says: Then let us begin.");
// arraylist for "if yes"
Simon.add("H");
Simon.add("E");
Simon.add("t");
Simon.add("R");
Simon.add("C");
Simon.add("D");
Simon.add("e");
Simon.add("h");
Simon.add("g");
Simon.add("'s");
Simon.add("a");
Simon.add("x");

  Random R = new Random();
  System.out.println(Simon.get(R.nextInt(Simon.size()))); 
Answered by SixBeeps (5332) [earned 5 cycles]
View Answer
Comments
hotnewtop
SixBeeps (5332)

From what I can gather, you want to randomly select a phrase from an ArrayList of phrases?

What you have works for that, just replace the letters with phrases.

xMisbahx (15)

@SixBeeps honestly, I was just guessing based on an error I fixed on a previous reply! anyway, thanks for the help!

Coder100 (18872)

Please clarify -- have what accept sentences/words instead of numbers?
The Scanner class?