class Listapalavras
{
public static void main (String args[])
{
String[] wordlistone = {"Oi","eu","ja","sei","java"};
String[] wordlisttwo = {"Foi","dificil","mas","consegui"};
String[] wordlistthree = {"Estudei","muito","é","10"};
//saber a quantidade de palavras nas variaveis acima
int tamanhoum = wordlistone.length;
int tamanhodois = wordlisttwo.length;
int tamanhotres = wordlistthree.length;
int aleatorioum = (int)(Math.random() * tamanhoum);
int aleatoriodois = (int) (Math.random() * tamanhodois);
int aleatoriotres = (int) (Math.random() * tamanhotres);
String phrase = wordlistone[tamanhoum] + " " + wordlisttwo[tamanhodois] + " " + wordlistthree[tamanhotres];
System.out.println(phrase);
}
}
Seguinte mensagem após compilado
java.lang.ArrayIndexOutOfBoundsException: 5
at Listapalavras.main(Listapalavras.java:18)
Exception in thread "main"
Process completed.