java 随机昵称
时间: 2023-10-11 20:22:26 浏览: 169
开发常用游戏昵称 java 随机
你可以使用 Java 中的 Random 类来生成随机昵称,例如:
```
import java.util.Random;
public class RandomNickname {
public static void main(String[] args) {
String[] adjectives = {"Happy", "Lucky", "Silly", "Crazy", "Wild", "Lovely", "Funny"};
String[] nouns = {"Cat", "Dog", "Rabbit", "Tiger", "Monkey", "Penguin", "Elephant"};
Random random = new Random();
String adjective = adjectives[random.nextInt(adjectives.length)];
String noun = nouns[random.nextInt(nouns.length)];
String nickname = adjective + noun;
System.out.println("Your random nickname is: " + nickname);
}
}
```
这段代码会从 `adjectives` 和 `nouns` 数组中随机选择一个形容词和一个名词,然后将它们拼接成一个随机昵称。
阅读全文