Results 1 to 5 of 5
  1. #1
    Juukamen is offline Member
    Join Date
    Oct 2011
    Location
    Tromsų
    Posts
    54
    Rep Power
    0

    Default Two dimensional Array

    Been running into some troubble again. here is the code i'm working with to get working

    Java 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);
    	 }
     }
    give error
    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

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,993
    Rep Power
    9

    Default 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!

  3. #3
    Juukamen is offline Member
    Join Date
    Oct 2011
    Location
    Tromsų
    Posts
    54
    Rep Power
    0

    Default Re: Two dimensional Array

    how do i change the constructor to one 2D array ?

  4. #4
    FallenBlade is offline Member
    Join Date
    Mar 2010
    Posts
    31
    Rep Power
    0

    Default 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[].

  5. #5
    Juukamen is offline Member
    Join Date
    Oct 2011
    Location
    Tromsų
    Posts
    54
    Rep Power
    0

    Default 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

  1. two dimensional array
    By shahnawazzzzzz in forum Java Software
    Replies: 2
    Last Post: 10-05-2011, 04:47 AM
  2. Help with Two Dimensional Array
    By johnjacob in forum New To Java
    Replies: 2
    Last Post: 06-03-2011, 08:22 PM
  3. 2 dimensional array
    By sehudson in forum New To Java
    Replies: 5
    Last Post: 02-20-2011, 11:56 PM
  4. about two dimensional array
    By matin1234 in forum New To Java
    Replies: 2
    Last Post: 06-01-2010, 11:09 AM
  5. two-dimensional array
    By kHim in forum New To Java
    Replies: 4
    Last Post: 11-16-2008, 07:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •