Results 1 to 5 of 5
Thread: Two dimensional Array
- 11-08-2011, 12:34 PM #1
Member
- Join Date
- Oct 2011
- Location
- Tromsų
- Posts
- 41
- Rep Power
- 0
Two dimensional Array
Been running into some troubble again. here is the code i'm working with to get working
give errorJava Code:class JavaTest { String a; private double[][] table1; public JavaTest(String a, double t1, double t2) { a = a; t1 = t1; t2 = t2; } } class Test { public static void main(String[] args){ double[][] data = {{12, -28}, {20, -12}}; JavaTest xxx = new JavaTest("Testing", data); } }
Java Code:G:\Coding\test.java:16: error: constructor JavaTest in class JavaTest cannot be applied to given types; JavaTest xxx = new JavaTest("Testing", data); ^ required: String,double,double found: String,double[][] reason: actual and formal argument lists differ in length 1 error Tool completed with exit code 1
- 11-08-2011, 02:15 PM #2
Re: Two dimensional Array
The JavaTest constructor takes exactly three arguments- a String, a double and a double. You're passing it two values- a String and a 2D array.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 11-08-2011, 02:25 PM #3
Member
- Join Date
- Oct 2011
- Location
- Tromsų
- Posts
- 41
- Rep Power
- 0
Re: Two dimensional Array
how do i change the constructor to one 2D array ?
- 11-08-2011, 02:27 PM #4
Member
- Join Date
- Mar 2010
- Posts
- 31
- Rep Power
- 0
Re: Two dimensional Array
The parameters section of the constructor states 2 doubles, t1 and t2:
public JavaTest(String a, double t1, double t2)
You need to replace those with a double array. double[].
- 11-09-2011, 11:10 AM #5
Member
- Join Date
- Oct 2011
- Location
- Tromsų
- Posts
- 41
- Rep Power
- 0
Re: Two dimensional Array
thanks for the answers, helped allot. at least this code will compile so i'm hoping it's working also.
Java Code:class JavaTest { String a; private double[][] table1; public JavaTest(String a, double[][]table2) { a = a; int t1 = table2.length; int t2 = table2[0].length; table1 = new double[t1][t2]; for(int i=0; i<t1; i++) { for(int j=0; j<t2; j++) { table1[i][j] = table2[i][j]; } } } } class Test { public static void main(String[] args){ double[][] data = {{12, -28}, {20, -12}}; JavaTest xxx = new JavaTest("Testing", data); } }
Similar Threads
-
two dimensional array
By shahnawazzzzzz in forum Java SoftwareReplies: 2Last Post: 10-05-2011, 04:47 AM -
Help with Two Dimensional Array
By johnjacob in forum New To JavaReplies: 2Last Post: 06-03-2011, 08:22 PM -
2 dimensional array
By sehudson in forum New To JavaReplies: 5Last Post: 02-20-2011, 11:56 PM -
about two dimensional array
By matin1234 in forum New To JavaReplies: 2Last Post: 06-01-2010, 11:09 AM -
two-dimensional array
By kHim in forum New To JavaReplies: 4Last Post: 11-16-2008, 07:21 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks