用JAVA编写一个使用随机数创建句子使用3个字符串数组String[] article = {"the","a","one"}; String[] noun = {"boy","dog","bird"}; String[] verb = {"jumped","ran","flew"}; 用随机数分别从3个数组中抽取3个单词连成句子
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/18 01:27:57
用JAVA编写一个使用随机数创建句子使用3个字符串数组String[] article = {"the","a","one"}; String[] noun = {"boy","dog","bird"}; String[] verb = {"jumped","ran","flew"}; 用随机数分别从3个数组中抽取3个单词连成句子
用JAVA编写一个使用随机数创建句子使用3个字符串数组
String[] article = {"the","a","one"}; String[] noun = {"boy","dog","bird"}; String[] verb = {"jumped","ran","flew"}; 用随机数分别从3个数组中抽取3个单词连成句子如the boy ran
用JAVA编写一个使用随机数创建句子使用3个字符串数组String[] article = {"the","a","one"}; String[] noun = {"boy","dog","bird"}; String[] verb = {"jumped","ran","flew"}; 用随机数分别从3个数组中抽取3个单词连成句子
import java.util.*; public class Test{ public static void main(String[] args){ String[] article = {"the","a","one"}; String[] noun = {"boy","dog","bird"}; String[] verb = {"jumped","ran","flew"}; System.out.println (getRandomString(article)+"\t"+getRandomString(noun)+"\t"+getRandomString(verb)); } public static String getRandomString(String[] str){ Random rand=new Random(); return str[rand.nextInt(3)]; } }