Iram Shahed Iram Shahed - 19 days ago 5x
Java Question

How to call random string from an array on Java?

String[] prompts = {"Describe to me in a sentence why this is a cool program.",
"Describe to me in a sentence how your day was.",
"Describe to me in a sentence what programming means to you.",
"Describe to me in a sentence why food is neccessary for humans."};

I want to call a random string from the array how should I report it?


Just need to randomly generate an index in the range of your array length

int i = new Random().nextInt(prompts.length);