我被要求創建一個程序,用於存儲數組中的一系列適當的名詞,形容詞和動詞。這些必須在程序運行開始時設置。與其詢問用戶,每次產生字母時,它只是從相應的數組中隨機選擇單詞。數組傳遞給表示模板的方法。在數組中選擇隨機字符串以打印消息
我是新來的java,這是我已經設法在下面完成,但是顯示錯誤說void不能轉換爲打印消息部分的字符串。如果有人能幫助我處理這個我正在努力的簡單問題,我會很高興,我不知道我是否正確地做到了這一點:/。任何幫助,將不勝感激:)
public static void arrays()
{
final String []noun = {"face", "eyes", "tender", "lips", "ears", "roses"};
Random random = new Random();
int rand1 = random.nextInt(noun.length);
final String []verb = {"enchant", "dazzle", "cuddle" , "lure", "desire", "dream" };
Random random2 = new Random();
int rand2 = random2.nextInt(verb.length);
final String []adjective = { "Alluring", "Angelic", "Adoring", "Appealing", "Attractive", "beautiful"};
Random random3 = new Random();
int rand3 = random3.nextInt(adjective.length);
String message = printmessage (noun[rand1], verb[rand2], adjective[rand3]);
JOptionPane.showMessageDialog(null, message);
}
// END arrays
public static String printmessage(String r1, String r2, String r3)
{
String result1;
String result2;
String result3;
String result4;
result1 = JOptionPane.showMessageDialog(null, "I would love to " + r2 + " " + r3 + " " + r1 + "\n");
return result1;
result2 = JOptionPane.showMessageDialog(null, "Your are my " + r1 + " " + r3 + " " + r2 + "\n");
return result2;
result3 = JOptionPane.showMessageDialog(null, "you always look great in that " + r1 + " , as you always do, since your so" + r3 + "\n");
return result3;
result4 = JOptionPane.showMessageDialog(null, "I get butterflies when I see you in" + r1 + " , you make me " + r2 + " , in your " + r3 + " world" + "\n");
return result4;
}
嗯,非常浪漫的代碼有 – Coffee 2014-11-21 17:06:04
我的猜測是你不是在主要方法中編寫代碼......而是寫在課堂上。顯示更多的代碼,所以我們可以看到有什麼問題.. – user1071777 2014-11-21 17:07:27
這就是說,所有問題都說明了,代碼還有什麼? @ user1071777 – Arpit 2014-11-21 17:10:34