方法一:
public class test {
public static void main(String[] args) {
Random random=new Random();
int num = random.nextInt(899999);
int code = num + 100000;
System.out.println(code);
}
}
方法二:
public class test {
public static void main(String[] args) {
int code = (int) (Math.random() * 900000 + 100000);
System.out.println(code);
}
}
方法三:
public class test {
public static void main(String[] args) {
StringBuilder code = new StringBuilder();
Random random = new Random();
for(int i=0;i<6;i++){
code.append(random.nextInt(10));
}
System.out.println(Integer.parseInt(String.valueOf(code)));
}
}