62,612
社区成员
发帖
与我相关
我的任务
分享
public class MathRandomChar {
public static char GetRandomChar(char ch1,char ch2){
return (char)(ch1+Math.random()*(ch2-ch1+1));
}
public static void main(String args[]){
//获取a~z之间的随机字符
System.out.println("任意小写字符:"+GetRandomChar('a','z'));
//获取A~Z之间的随机字符
System.out.println("任意大写字符:"+GetRandomChar('A','Z'));
//获取0~9之间的随机字符
System.out.println("0到9任意数字字符:"+GetRandomChar('0','9'));
}
}