I am having a hard time figuring out how to incorporate my sum function for a 1 dimensional array into my sum function for a 2 dimensional array. I wrote my function for a code and it does compile through, but the output doesn't come out with the sum, but outputs zero instead. I want to understand how to play with these arrays, and understand how to play around with overloaded functions. I have other aspects of arrays I want to code into this program, such as trying to flatten a 2d array into a 1d array, and also make a boolean function to see if all the elements in a 2d array are the same length, and I feel like if I can understand how to make this sum function work with the 2d array, I will be able to figure out how to do the rest with trial and error.
Also, if your class name wouldn't be as it is, I might wouldn't tell you, but:
Class names suppose to start with an upper case, that is conventional, so please to follow that.
In Java multidimensional arrays are not truly 2D or 3D... these are array of arrays. Look up on google for the explaining articles (in case you are curious). So better call the class MultidimensionalArray.
You're not doing anything with the return value in line ten, sum(r).
All things are lawful, but not all things are profitable.
posted 4 years ago
I'm trying to recall my previous sum function for a 1d array into my 2d array function, but I'm not sure how to input it so that it shows the return value for sum(r). In my head the sum function should be working, but for each element in the 2D array when I recall the function, and when I input return sum, it should have the sum of all the numbers in my 2D array, but that's not the case.