Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6540463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:58:56+00:00 2026-05-25T10:58:56+00:00

I don’t really know how to describe my issue, so I’ll just show a

  • 0

I don’t really know how to describe my issue, so I’ll just show a code example:

int[][][] mat;
int n;
int specificValue;

for (int i = 0; i < n; i++) {
    if(mat[i][n-i][3] != specificValue) {
        doStuff();
    }
}

I’m looking up Integer values in a 3d-array. For each field I have to use one of these:

  • a counter running from zero to n
  • a counter running from n to zero
  • a fixed value

So i’ve tried to build a Method that would save me from writing this for loop about 20 times, but i failed, so that’s where i need help. My idea was something like this:

search(Loop.UP, Loop.DOWN, Loop.FIXED);

where “Loop” would be an enum representing one of my possibilities, but I don’t know how to implement it or if this is even possible in Java without hardcoding every possible combination.

Hope you can help 🙂


OK, more specific… with my setup i’m drawing a vector through this 3d-array, a diagonal to be specific and i want to know what values are on this vector and only on this vector.

And because there is more than one possibility to draw such a vector, i’d like to have a more general method to get to the values. My search could just be as simple as

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

which would be a simple for-loop with one counter, but also

search(Loop.DOWN, Loop.UP, Loop.UP);   // through all three planes
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:58:57+00:00Added an answer on May 25, 2026 at 10:58 am
    Path pathX = new Path.Up();
    Path pathY = new Path.Down(n);
    Path pathZ = new Path.Fixed(3);
    
    for (int i = 0; i < n; i++) {
        if(mat[pathX.pos(i)][pathY.pos(i)][pathZ.pos(i)] != specificValue) {
            doStuff();  
        }
    }
    

    where

    public interface Path {
        public int pos(int i);
    
        public static class Up implements Path {
             @Override public int pos(int i) { return i; }
        }
    
        public static class Down implements Path {
             private int n;
             public Down(int n) { this.n = n; }
             @Override public int pos(int i) { return n - i - 1; }
        }
    
        public static class Fixed implements Path {
             private int v;
             public Down(int v) { this.v = v; }
             @Override public int pos(int i) { return v; }
        }
    

    I didn’t use an Enum because Down depends on n and Fixed on some value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't be scared of the extensive code. The problem is general. I just provided
Don't really know how to formulate the title, but it should be pretty obvious
I don't know why, but this code worked for me a month ago... maybe
Don't be frightened, its a very basic code. Just wanted to check with you
Don't know if this is possible, but I have some code like this: val
Don't think there's much to say, here's my code for (int i = 0;
Don't know whether I'm having a "thick day" - but I just wondered what
Don't know why this conversion fails. SELECT CAST('32.999' AS INT) throws the error saying
don't know better title for this, but here's my code. I have class user
Don't know how to frase this but I found this code wich works as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.