编写方法:public static List generateNameList(int n);,生成n个字符串的NameList并返回的代码
时间: 2024-05-28 20:09:28 浏览: 60
基于python tkinter的点名小程序功能的实例代码
public static List<String> generateNameList(int n) {
List<String> nameList = new ArrayList<>();
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random random = new Random();
for (int i = 0; i < n; i++) {
StringBuilder name = new StringBuilder();
int length = random.nextInt(10) + 1; // Assume names are between 1 and 10 letters long
for (int j = 0; j < length; j++) {
int index = random.nextInt(characters.length());
name.append(characters.charAt(index));
}
nameList.add(name.toString());
}
return nameList;
}
阅读全文