Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# 6x6x6x6x6 array representation

Eric Racin
Ranch Hand
Posts: 39
I need this multi-dimensional array (6x6x6x6x6 = 7776 elements):
This is a portion of the data:
0 0 0 0 0 445
91 151 179 180 155 544
224 368 437 435 370 673

How do I know where to put the brackets?
public int iArray[][][][][] = ?
Do I do this?
{{{{{{ 0, 0, 0, 0, 0, 445}
{ 91, 151, 179, 180, 155, 544}
{224, 368, 437, 435, 370, 673}

Kevin Workman
Ranch Hand
Posts: 151
• 1
Good lord why would you want to use brackets to instantiate a 6x6x6x6x6 array? I would actually argue that using an array of that size is a sure sign of a bad design, but that's another point.

Why don't you just do something like this:

Then loop through to set each index?

But, again, there is probably a much better way to go about doing this without using such a ridiculous array.

PS- Are you sure you don't just need a 2-dimensional array?

Darryl Burke
Bartender
Posts: 5167
11
It helps to remember that in Java, a multi dimensional array is an array of arrays.

So an int[] is an array of ints
an int[][] is an array of int[]
...
an int[][][][][] is an array of int[][][][]

I agree with Kevin that having to use a 5 dimensional array is likely an outcome of bad design, and there is probably a better way of doing whatever it is you are doing. Would you like to share that? the problem, not any solution that has come to your mind.

Eric Racin
Ranch Hand
Posts: 39
Point well taken. The real problem is that are production Tomcat Servlet
will not read anything from a file (while the test Server works fine!)
This is a brute force attempt to have the data within the Servlet itself, but
I am confused as to where to put the brackets.

(The 6x6x6x6x6 array results from the possible permutation of choices from the user:
5 fields with 6 choices per field)

Rob Spoor
Sheriff
Posts: 21092
85
Let's focus on the main problem - why you can't read from the file. Are you reading the file from the right location? Are you using ServletContext.getRealPath?

Eric Racin
Ranch Hand
Posts: 39
getRealPath() is a good idea. However, from my research it looks like
it will return \index.html.
getPathTranslated() will probably return something like
\Tomcat\webapps\Root\index.html

The needed file was opened successfully at
\Tomcat\bin on one Server.

On the problem Server I also placed it in
\Tomcat4.1\webapps\ROOT and
\Tomcat4.1\webapps\carbonapp3\WEB-INF\classes

I guess I could sprinkle it throughout the directories but I feel like I
am on a wild goose chase. The permissions have been checked as
well as the Server's security model. That is why I was giving up
and placing the array within the Servlet.

Wouter Oet
Bartender
Posts: 2700
Eric please UseOneThreadPerQuestion. You already asked the question here. I'll close that one because this one has more activity.

 Don't get me started about those stupid light bulbs.