import java.util.Random;
import java.util.Scanner; // 1. Importación agregada para leer la entrada

public class Main {

    public static void main(String[] args) {
        Scanner teclado = new Scanner(System.in);
        
        // 2. Lee el número que escribas en el cuadro de Entradas
        int tama = teclado.nextInt(); 

        // 3. Valida que sea impar y mayor a 0 antes de ejecutar el resto
        if (tama > 0 && tama % 2 != 0) {
            llenarMatriz(tama);
        } else {
            System.out.println("Error: Debes escribir un número entero impar (ej. 5, 7, 9).");
        }
    }

    // Método para llenar la matriz con números aleatorios y llamar a las figuras
    public static void llenarMatriz(int x) {
        String[][] abc = new String[x][x];
        Random aleatorio = new Random();
        String mostrar = "";

        // Llenado de la matriz con números aleatorios del 0 al 99
        for (int fila = 0; fila < x; fila++) {
            for (int col = 0; col < x; col++) {
                abc[fila][col] = String.valueOf(aleatorio.nextInt(100));
                mostrar += String.format("%-4s", abc[fila][col]);
            }
            mostrar += "\n";
        }

        // Muestra la matriz original en la consola
        System.out.println("=== MATRIZ ORIGINAL ===");
        System.out.println(mostrar);

        // Llamada a los métodos para dibujar cada figura
        x(x, abc);
        letraL(x, abc);
        letraT(x, abc);
    }

    // 1. Método para dibujar la letra X
    public static void x(int x, String[][] arreglo) {
        String concatenar = "";
        int otraV = x - 1;

        for (int fila = 0; fila < x; fila++) {
            for (int col = 0; col < x; col++) {
                if (fila == col || otraV == col) {
                    concatenar += String.format("%-4s", "--");
                } else {
                    concatenar += String.format("%-4s", arreglo[fila][col]);
                }

                if (otraV == col) {
                    otraV--;
                }
            }
            concatenar += "\n";
        }

        System.out.println("=== FIGURA X ===");
        System.out.println(concatenar);
    }

    // 2. Método para dibujar la letra L
    public static void letraL(int xx, String[][] arregloLetraL) {
        String concatenar = "";
        int otraV = xx - 1;

        for (int fila = 0; fila < xx; fila++) {
            for (int col = 0; col < xx; col++) {
                if (0 == col || otraV == fila) {
                    concatenar += String.format("%-4s", "--");
                } else {
                    concatenar += String.format("%-4s", arregloLetraL[fila][col]);
                }
            }
            concatenar += "\n";
        }

        System.out.println("=== FIGURA L ===");
        System.out.println(concatenar);
    }

    // 3. Método para dibujar la letra T
    public static void letraT(int xx, String[][] arregloLetraT) {
        String concatenar = "";
        int otraV = xx - 1;

        for (int fila = 0; fila < xx; fila++) {
            for (int col = 0; col < xx; col++) {
                if (0 == fila || (otraV / 2) == col) {
                    concatenar += String.format("%-4s", "--");
                } else {
                    concatenar += String.format("%-4s", arregloLetraT[fila][col]);
                }
            }
            concatenar += "\n";
        }

        System.out.println("=== FIGURA T ===");
        System.out.println(concatenar);
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: