编写一个采用随机函数生成句子的游戏。现在有4个字符串数组:artilce、noun、verbpreposition,它们的内容分别是:  the、a、one、some、any;  boy、girl、dog、town、car;  drove、jumped、ran、walked、skipped;  to、from、over、under、on。  依照句法要:article+noun+verb+prepsition+article+noum,编写程序以产生20句子。

解决方案 »

  1.   

    晕,这个问题~~书是哪本?java程序设计教程,哈哈。我刚做过,代码贴给你吗?
    你还动动脑子吧!
      

  2.   

    String s = article[(int) (Math.random() * article.length)] + " "
    + noun[(int) (Math.random() * noun.length)] + " "
    + verb[(int) (Math.random() * verb.length)] + " "
    + prepostion[(int) (Math.random() * prepostion.length)]; StringBuffer buffer = new StringBuffer(s);
    buffer.setCharAt(0, Character.toUpperCase(s.charAt(0))); str[i] = buffer.toString() + ".\n";

    outputArea.append(str[i]);
    这个给你整个程序就给了~~哎,好好学习才素王道