使用Math.random()函数将int转为char
a-z:97-122
A-Z:65-90
设定起始ASCII码值
public static void main(String[] args) { /* * a-z:97~122 * A-Z:65~90 * */ char randomChar = (char) (Math.random() * 58 + 65); if (randomChar >= 65 && randomChar <= 90) { System.out.println(randomChar); System.out.println("Yes"); } else { System.out.println(randomChar); System.out.println("no"); } }