mercredi 30 novembre 2016

java looping in 2d array with if conditions statements

im trying to do a certain project and there is this part in which i want to loop in a 2d array and if the certain value of i & j then do something..

to be more specific my 2d array is defined for files and users and the attached photo might explain well, i want for example when index i=0 and j=0 equals 1 then print out that user 1 can write in file, i was able to iterate over the array and find the indexes where 1's occur in the array in the following code:

my 2d array defined

public class test {

public int counteri=0;
public int counterj=0;

 public void readpermission (int[][] array)
{
    for(int i=0; i<2; i++)
    {
        for(int j=0; j<6; j++)
        {
            if(array[i][j]==1)
            {
                counterj = j;
                counteri=i;
                System.out.println("found 1's at index =" + counteri +" "+ counterj );


            }


            }


        }

    }



}

found 1's at index =0 0,

found 1's at index =0 1

found 1's at index =0 4

found 1's at index =1 1

found 1's at index =1 2

found 1's at index =1 3

found 1's at index =1 4

found 1's at index =1 5

when the first value is 0 0 i want an output that user 1 can write in file 1 and when th output is 0 1 i want an output stating that user 1 can read in file 1 and so on ...

Aucun commentaire:

Enregistrer un commentaire