用java写一个生成5位数的验证码
时间: 2024-05-06 18:20:47 浏览: 96
Java随机生成六位验证码
5星 · 资源好评率100%
```java
import java.util.Random;
public class GenerateVerificationCode {
public static void main(String[] args) {
String verificationCode = generateVerificationCode();
System.out.println("Verification code: " + verificationCode);
}
public static String generateVerificationCode() {
Random random = new Random();
int code = random.nextInt(90000) + 10000; // 生成10000-99999之间的随机整数
return String.valueOf(code);
}
}
```
阅读全文