package com.lu;
import java.util.Random;
import java.util.Scanner;
public class Text2 {
public static void main(String[] args) {
//开发验证码
Scanner input = new Scanner(System.in);
System.out.println("请输入指定位数的:");
randomNumbers(input.nextInt());
}
public static String randomNumbers(int n){//生成随机数
Random r = new Random();
String b ="";
for (int i = 1; i <= n; i++) {
int a = r.nextInt(3);
switch (a){
case 0 :
b += r.nextInt(10);//数字
break;
case 1 :
b += (char)r.nextInt(65,91);//大写字母
break;
case 2 :
b += (char)r.nextInt(97,123);//小写字母
break;
}
}
System.out.println(b);
return b;
}
}
java随机
最新推荐文章于 2024-11-11 00:03:55 发布