-1
這是我的代碼到目前爲止,我怎麼得到這個工作,因爲我努力打印一個句子,更不用說隨便了。如何獲取此代碼從每個數組中選擇一個隨機單詞來打印一個句子?
我需要從每個陣列一個字的陣列
import java.util.Random;
public class MadLibs {
public static void main(String[] args) {
String[] nouns = null;
String[] verbs = null;
String[] adjec = null;
String[] adver = null;
nouns[0] = "Lion";
nouns[1] = "Stewart";
nouns[2] = "Timbaktu";
nouns[3] = "Kilamanjaro";
nouns[4] = "Hawai";
nouns[5] = "Frog";
nouns[6] = "Russia";
nouns[7] = "Dimethyltryptaline";
nouns[8] = "Dog";
nouns[9] = "Badness";
verbs[0] = "hear";
verbs[1] = "achieve";
verbs[2] = "smash";
verbs[3] = "destroy";
verbs[4] = "smoke";
verbs[5] = "burn";
verbs[6] = "rose";
verbs[7] = "speak";
verbs[8] = "type";
verbs[9] = "be";
adjec[0] = "Tangy";
adjec[1] = "Sour";
adjec[2] = "Smooth";
adjec[3] = "Sticky";
adjec[4] = "Soft";
adjec[5] = "Black";
adjec[6] = "Whispering";
adjec[7] = "Resonant";
adjec[8] = "Wide";
adjec[9] = "Long";
adver[0] = "Truthfully";
adver[1] = "Endlessly";
adver[2] = "Painfully";
adver[3] = "Tirelessly";
adver[4] = "Beautifully";
adver[5] = "Uneasily";
adver[6] = "Wickedly";
adver[7] = "Briskly";
adver[8] = "Now";
adver[9] = "Last";
String random = (verbs[new Random().nextInt(verbs.length)]);
System.out.println("Does your" + verbs + " your " + adjec + nouns + adver);
}
}
'Math.random'或'Random' – Korashen
你應該先初始化數組 - '的String []名詞=新的String [10];'。 –