mardi 12 novembre 2019

How can i randomly select only one size in a two-dimensional array

String[] dizi_paragraf = dosya.split("\n");
for (int i = 0; i < dizi_paragraf.length; i++) {
    String[] dizi_cumle = dizi_paragraf[i].split("\\.");
    String[][] dizi_total = new String[dizi_paragraf.length][dizi_cumle.length];
    int[][] dizi = new int[dizi_paragraf.length][dizi_cumle.length];
    for (int j = 0; j < dizi_cumle.length; j++) {
        dizi_total[i][j] = dizi_cumle[j];
        dizi[i][j] = j;
        System.out.println(dizi[i][j]);
    }
}

Output:

0-0
0-1
1-0
1-1
1-2
2-0
3-0
3-1
4-0
4-1
5-0
5-1
5-2
5-3

I want this:

    0-1
    0-0
    1-1
    1-0
    1-2
    2-0
    3-1
    3-0
    4-0
    4-1
    5-3
    5-1
    5-0
    5-2

This is an example. The value in j for each i changes randomly but until j length. How can I do this? Have you any ideas? For example, it should produce 0 or 1 for index 0. It should produce 0.1 or 2 for the 1st index. 2. You should take only 0 for indis. etc. Just example. This can be change. I take this dynamically.

"i" must be constant. But j should be chosen randomly. for indice 0, j value: 0 and 1. This should be chosen randomly. for indice 1, j value: 0,1 and 2. This should be chosen randomly.




Aucun commentaire:

Enregistrer un commentaire