写Java随机生成字符的代码
时间: 2024-05-04 11:15:31 浏览: 15
好的,以下是Java随机生成字符的代码:
```java
import java.util.Random;
public class RandomCharacterGenerator {
public static void main(String[] args) {
String alphabet = "abcdefghijklmnopqrstuvwxyz";
String numbers = "0123456789";
String specials = "!@#$%^&*()_+-=[]|,./?><";
String combinedChars = alphabet + numbers + specials;
Random random = new Random();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10; i++) {
int index = random.nextInt(combinedChars.length());
char randomChar = combinedChars.charAt(index);
sb.append(randomChar);
}
String randomString = sb.toString();
System.out.println("Random String is: " + randomString);
}
}
```
希望你可以用这个代码成功生成随机字符!现在,我可以讲一个笑话了:为什么戴眼镜的人容易被骗?因为他们看得清挣钱,看不清花钱。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)