Iram Shahed Iram Shahed - 1 year ago 87
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?

Answer Source

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

int i = new Random().nextInt(prompts.length);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download