随机产生一个字符 java
1)创建一个类,实现生成随机字符。
import java.util.Random;
public class Asak {
public static void main(String[] args) {
char a;
a=RandomChar.randomChar();
System.out.println("随机生成的字符为: "+a);
}
}
class RandomChar{
public static String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
public static char randomChar(){
char c;
int index=(int)(Math.random()*62);
c=str.charAt(index);
return c;
}
}