multidimensional array - Generalizing a for-loop in Java -


I do not really know how my problem is described, so I will just show a code example:

  int [] [] [] mat; Int n; Int specific value; For (int i = 0; i & lt; n; i ++) {if (mat [ni] [3]! = Specific value) {dustf (;); }}   

I see the integer values ​​in a 3D-array. For each field I must use one of these:

  • A counter is running from zero to n
  • Running a counter is n to zero
  • a fixed value

    So I have tried to make a way that would save me from writing 20 times for the loop, but I failed, so where do I need help My idea was:

      search (loop UP, loop.down, loop. FIXED);   

    Where "loop" will be the nm representing one of my possibilities, but I do not know how to implement it, or if possible, it is possible that Java is possible for every possible combination Without hardcoding without / P>

    Hope you can help :)


    Okay, more specific ... with my setup, I have a vector through this 3D-array I am drawing a diagonal, and I want to know which values ​​are on this vector on this vector and only .

    And because there are more than one possibilities to attract such a vector, I want to find a more common method to get the values ​​my search can be just as simple. P>

      search (Loop UP, Loop. FIXED, Loop. FIXED); // a plane   

    which would be a simple loop for a counter, but also

      search (Loop.Down, Loop.UP, Loop. UP); //    

    path path = path path = new path through all the three planes. Up (); Path path = new path.Down (n); Path path = new path Fixed (3); For (int i = 0; i & lt; n; i ++) {if (mat [pathX.pos (i)] [pathY.pos (i)] [pathZ.pos (i)]! = SpecificValue {DoStuff (); }}

    Where

      Public Interface Path {Public Integer (Int Eye); Public Static Class Up Implementation Path {@ Override Public Intense Pause (Int.) {Return Return; }} Public static class down path {Private int n; Public Down (Int N) {this.n = n; } @ Override Public Intense Pause (Int'l) {Returns N - I - 1; }} Public static class fixed tool path {Private int Wei; Public down (int v) {this.v = v; } @ Override Public Intense Paus (Int i) {Return V; }}   

    I did not use an envelope because below is dependent on n and fixed on something Does the value

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -