How to call a method in a Java array, please help!?
-
I'm trying to compile my code here. I need to pass the two-dimensional array multTable to the method makeArray, however I keep getting the same error that tells me method makeArray in class multiplicationTable1 cannot be applied to given types; makeArray(multTable);. My code is listed below, please help me! public class multiplicationTable1 { public static void main(String[] args) { System.out.println ("Multiplication Table of 1's Through 9's"); int arraySize = 9; int[][] multTable; makeArray(multTable); printArray(multTable); } public static int [][] makeArray (int size) { //create a 2-dimensional array of int int[][] newArray = new int[size][size]; //populate array with values for(int row=0; row < newArray.length; ++row) for(int col=0; col < newArray.length; ++col) newArray[row][col] = (row + 1) * (col + 1); //return array to caller return newArray; } public static void printArray(int[][] newArray) { for(int row=0;row < newArray.length; ++row) for(int col=0; col < newArray.length; ++col) System.out.print("\t"+newArray[row]); System.out.println("\n"); } }
-
Answer:
I see what you're trying to do. You want to give makeArrsy(..) just the size and have it return the array. This is what you wanted: int[][] multTable = makeArray(arraySize);
K4G3D at Yahoo! Answers Visit the source
Other answers
I see what you're trying to do. You want to give makeArrsy(..) just the size and have it return the array. This is what you wanted: int[][] multTable = makeArray(arraySize);
modulo_f...
Try setting multTable to null when you define the variable.
godfatherofsoul
Try setting multTable to null when you define the variable.
godfatherofsoul
Related Q & A:
- How to invoke a method at particular time asynchronously every day in Mac application?Best solution by Ask Different
- How to call a popup from a link inside another popup?Best solution by stackoverflow.com
- How to call a method once everyday?Best solution by Stack Overflow
- How to call a function with parameter in a bash script?Best solution by tldp.org
- Advice on what to do to become a police officer? please help?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.