How to randomly select a letter (A-Z) in Java?

If I want to randomly select a letter between a and Z, I assume I have to use the random class:

Random rand = new Random();

But since this only produces numbers, what do I need to do to apply it to letters?

Solution

Random r = new Random();
Random r = new Random();
char c = (char) (r.nextInt(26) + 'a');
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>