-2

Hello and thank you for reading this. I have written code that fills a 2d triangular array, but it only fills with lower case letters. How do I get it to also fill with uppercase letters?

Here is a small part of the code:

public static void fillSpecialMatrice(char[][] matrice) {
   Random random = new Random();
   for(int i = 0; i < matrice.length; i++) {
      for(int j = 0; j < matrice.length-i; j++) {
         matrice[i][j] = (char) (random.nextInt(26) + 'a');
      }
   }
}

How the triangular matrix looks when printed:

enter image description here

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
Leksus
  • 1

1 Answers1

1

You can randomize upper and lower-cases as well. Something like this:

public static void fillSpecialMatrice(char[][] matrice) {
    Random random = new Random();
        for(int i = 0; i < matrice.length; i++) {
            for(int j = 0; j < matrice.length-i; j++) {
                   case_int = random.nextInt(2);
                   case_char = (case_int == 0 ) ? 'a' : 'A';
                   matrice[i][j] = (char) (random.nextInt(26) + case_char);
     }
    }
  }
vish4071
  • 5,135
  • 4
  • 35
  • 65