How do I calculate the sum of a two dimensional arrays values?

Given the declaration: int[][] values = {{30},{10},{90}}
Write a class call Q18, and in this class write a method call doIt()
that takes the following variable "values" as declared above, as an
argument, and sums the values in the two dimensional array, to return
an int. Print this value to the standard output.

here is what I have so far:

It doesn't compile. I'm guessing it has to do with the for statement being in a method? I know my code is far off but my mind has been clogged from all these assignments and I can't seem to think straight.

Any help I can get so that I can figure out how to answer the question and fix the code would be greatly appreciated!

And your above code will not give you what you desire, even though you make appropriate change..
You need to call the method doIt() from your main()..
Also, rather than initializing the array in your doIt() method, you should probably do it in main itself, and pass it as a parameter to the method doIt()

Going back to the instructions you were given:
"Write a class call Q18, and in this class write a method call doIt() that takes the following variable "values" as declared above, as an argument, and sums the values in the two dimensional array, to return an int."

Does your doIt() method take an argument?

Does it return an int?

What do you think you need to do to write it so that it does exactly what the instructions tell you?

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here

I keep trying to follow the directions and change things but I can't get past the compilation errors. I have looked over my textbook multiple times and it does not mention multidimensional arrays used with for loops. I know this is easy stuff which i'm having trouble with, but I just can't for the life of me figure it out.

First, look at Winston's last post. How would you declare a doIt() method that takes values as an argument, and that returns an int? Don't try to write any code for that method before you answer that question. Writing the code inside the method is step two.

Post here what you think the method declaration should look like. Then we'll proceed to help you write the code for it.

a piece of advice - never write more than 2-3 lines of code before you re-compile. If you write 100 lines then compile, you're bound to get dozens of errors. This can be very discouraging. if you write 2 lines at a time, then you know where to focus your attention. You should also test after each successful compilation. This may require to to write lots of dummy code that you quickly delete, but it actually saves time in the long run. I am constantly writing System.out.println() statements that print things like: