• 0

Return random text from string


Question

import java.util.Random;

public class teststring {
public static void main(String[]args){
	Random RG = new Random();
	String[] fruit = {"I am not your friend", "oh, yeah"," Think again"};

	fruit = RG.getRandom();

	System.out.println(fruit);

}
}

Anyone know what i am missing? i want to have the code randomly return one of those text from that parameter

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Don't you want to do something like this?

System.out.print(fruit[RandomNumber]);

You are reassigning fruit to a value, and I'm not sure what getRandom is, its not part of the java API

So if you set the seed to be from 0 to 2 inclusive, It will choose a random string in that array.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.