Druk tylko po skosie

0

Mam problem chciałbym wydrukować tylko sam skos tablicy dwuwymiarowej i te zera wyrzucić ale nie wiem jak jak to zrobić. Zależy mi na podpowiedzi:)



        System.out.println("Pokaz skos");
        int[][] rand = {
                {1, 5, 6, 9, 3},
                {4, 2, 6, 7, 9},
                {4, 3, 5, 7, 9},
                {4, 1, 3, 7, 5},
                {4, 5, 7, 7, 7},
        };
        for (int x = 0; x < rand.length; x++) {
            for (int y = 0; y < rand.length; y++) {
                if (x == y) {
                    rand[x][y] = rand[x][y];
                }else{
                    rand[x][y] = 0;
                }
                System.out.print(rand[x][y] + " ");
            }
            System.out.println();
        }
    }
    }```
1
        System.out.println("Pokaz skos");
        int[][] rand = {
                {1, 5, 6, 9, 3},
                {4, 2, 6, 7, 9},
                {4, 3, 5, 7, 9},
                {4, 1, 3, 7, 5},
                {4, 5, 7, 7, 7},
        };
        for (int x = 0; x < rand.length; x++) {
            for (int y = 0; y < rand.length; y++) {
                final String element = x == y ? String.valueOf(rand[x][y]) : " ";
                System.out.print(element + "  ");
            }
            System.out.println();
        }
0

@KamilAdam: Dzięki

1 użytkowników online, w tym zalogowanych: 0, gości: 1