Java char type random value

Description

Java char type random value

import java.util.Arrays;
import java.util.Random;

public class Main {
  public static void main(String[] args) {
    char array[][] = new char[5][5];
    Random rnd = new Random();
    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        int x = rnd.nextInt(5); // 0 to 4
        array[i][j] = (char)('a'+x);
      }/*from   w  ww  .  j  a  v  a 2s . com*/
    }
    System.out.println(Arrays.deepToString(array));
  }
}



PreviousNext

Related