/** * @description: 随机生成单词 * a生成单词个数;b生成单词最长长度 */ public static String[] words(int a, int b){ String[] words = {}; if(a>0 && b>0) { words = new String[a]; String[] red = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; for(int i=0;i<a;i++) { String word = ""; //随记单词的长度 int randb = new Random().nextInt(b); for(int j=0;j<=randb;j++) { int randa = new Random().nextInt(26); //随记单词的一个字母 if(j==0) { word = red[randa]; }else{ word += red[randa]; } } words[i] = word; } System.out.print("生成的随机单词:"); for (int i=0; i<words.length; i++){ if(i==0) { System.out.print(words[i]); }else{ System.out.print(","+words[i]); } } System.out.println("-------words方法结束"); } return words; }
随机生成单词
最新推荐文章于 2024-09-10 09:32:36 发布