[Edit by Winston: Broke up that very long line 21]
You are declaring int arrays, which are not multidimensional. Java only supports 1‑dimensional arrays. What you are declaring is arrays of arrays. Anyway, you might declare arrays of arrays, but you are assigning those references to ordinary arrays.
you should not have a ROWS or COLUMNS field. You should get the length of an array out of the array, via its .length field. That way you can have an 11‑element array and still get all its elements.
You have misunderstood the format of the printf arguments. You should have one String with all the % tags in, followed by a comma‑separated list of arguments. You should not need tab characters, because you can use the numbers after % instead. Never use the linefeed character \n. Use the %n tag instead.
Is this what you're looking for:
In any case, you should think of a "multi-dimensional array" as an array whose elements are other arrays. So when you declare an array like
What this means is: give me an array that stores arrays of int values, and make it one that can store 3 arrays which in turn can store 10 int values.
What you're doing in you code is something different, and illegal:
This means, give me an array that stores arrays of int values and make it one that doesn't store arrays of int values, but these specific int values instead. That doesn't make any sense to the compiler.
What would make this legal is to change the syntax to the following:
Simply surround the int values with curly brackets, and the compiler will know to treat them as an array initializer, meaning you'll en up with an array of arrays that each hold exeactly one int value.
At any rate, while it's certainly possible to represent a table as an array of arrays, it wouldn't be my first choice in this case, as you need to store different data types (int's and String's). Is the use of a "multi-dimensional array" a requirement of the assignment?
Devin Walton wrote:The general idea behind it it that you have to print off a table with 10 columns and three rows. In one column you have names, the other you have to print off their over risk for high cholesterol, and in the third you have to print off their risk of high ldl cholesterol...
Well, all these arrays seem to refer to a specific thing - a Patient - so why not write a Patient class?
Then you could gather all that separate information into a single array, viz:or alternatively, simply set it up from scratch:
Now you only have one array to worry about, and it contains objects that define exactly what you want - and that's how Object-Orientation works.
(well, part of it )