In Java how do you randomly select a letter (a-z)?

后端 未结 9 1427
北海茫月
北海茫月 2021-01-04 03:50

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();

Bu

9条回答
  •  甜味超标
    2021-01-04 04:29

    alter version of @Michael Barker

        Random r = new Random();
        int c = r.nextInt(26) + (byte)'a';
        System.out.println((char)c);
    

提交回复
热议问题