Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla wrote:Both are quite a lot different.
The first one is trying to mimic the use of initialization block, but then its not a valid syntax of initialization block.
The second one is initializing the array along with defining it. But the first is is defining it correctly but its a syntactically incorrect approach to initialize it.
Gabe Evan wrote:
and now my output is
It's looking better but can you tell me why that last 0 gets picked up on the first row? It's supposed to be the first number in the second row. I'm playing around with a if statement right now
Stefan Evans wrote:I would actually suggest writing them in two seperate loop rather than a nested loop.
ie:
write out x axis values, separated by tabs all on one line
write out y axis values, one per line.
I'm not certain a two dimensional array is appropriate for this. I think it would be better modeled as two separate arrays.
ie:
int[] xAxis = {60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0, -5, -10, -15};
int[] yAxis = {0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50};
alternatively as the scales are linear you might dispense with these arrays completely and specify an axis with "startNumber", "step" and "howMany"
e.g. your x axis could be specified as:
startNumber: 60
step: -5
howMany: 16 (or endNumber: -15)
You will still need the array of arrays for the actual values.
Stefan Evans wrote:Almost anything can be done.
I am just of the opinion that your axes should be defined separately to your data.
When you present it on screen, sure you want them in that grid format, the first row being your x axis values, the first column being your y axis values.
But that doesn't necessitate that you STORE them in all within the same data structure.
Just my 2 cents of course :-)