Results 1 to 10 of 10
Thread: Matrix
- 10-05-2011, 02:19 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
- 10-05-2011, 02:28 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Re: Matrix
You could use four separate numbers, as in:
... but that doesn't scale very well (you most certainly don't want to take that route with a 100x100 matrix); or you could simply define a two dimensional array:Java Code:double a00, a01, a10, a11;
kind regards,Java Code:double[][] a= new double[2][2];
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-05-2011, 02:35 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
Re: Matrix
Hey thanks for you help, but now i got this:
Do i need to change the field too? Sorry this is like my second time java:$Java Code:public class Matrix { private int[][] x1,y1; /** * Constructor for objects of class Matrix */ public Matrix() { double[][] a= new double[2][2]; }
And yeah im so dumb, i want to print the result of the 2x2 matrix.
Can i do that with a System.out.println?Last edited by sunde887; 10-05-2011 at 04:29 PM. Reason: Added code tags, [code]...[/code]
- 10-05-2011, 04:21 PM #4
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
Re: Matrix
no one can help me?
I just cant fix it...
What's wrong in my code?
I can make a object, but when i excute "public void print()" it gives "double" back and nothing more:(
Java Code:public class Matrix { // instance variables - replace the example below with your own private int[][] x1,y1; /** * Constructor for objects of class Matrix */ public Matrix(double matr) { double[][] a= new double[2][2]; } public void print() { System.out.println(double.class); } }Last edited by sunde887; 10-05-2011 at 04:29 PM. Reason: Added code tags, [code]...[/code]
- 10-05-2011, 04:28 PM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Matrix
There are a lot of problems. Including, why are you printing double.class? Why do you expect it to print anything other than double? Why do you give the constructor an argument and not use it? Why is the argument a double, and not a matrix? Why do you create a local 2d array in the matrix constructor? Do you ever initialize the instance variables? Why is the instance variable of type int? Why do you have two 2d arrays as instance variables?
Also, please use code tags when posting code: [code] YOUR CODE HERE [/code]Last edited by sunde887; 10-05-2011 at 04:31 PM.
- 10-05-2011, 04:42 PM #6
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
Re: Matrix
I changed the double.class but the problem is that i dont know what to use to make it print.
I did make a setter but i dont know if it will works because i cant see the result of it.
How can i make the argument a matrix?
And how can i make a matrix than?
Greets,Java Code:public class Matrix { /** * Constructor for objects of class Matrix */ public Matrix() { int [ ] [ ] scores = new int [ 2 ] [ 2 ] ; } public void setTable() { int [ ] [ ] scores = { { 20, 18}, { 18, 20} }; }; public void print() { System.out.println(); } }
- 10-05-2011, 04:48 PM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Matrix
Lesson: Object-Oriented Programming Concepts (The Java™ Tutorials > Learning the Java Language) may be of help to you. Look into how to use the constructor properly. The setter, and the constructor, should initialize, or change, the instance variable of the class. Obviously the instance variable should be the two dimensional array(could also be 2 1D arrays if you don't want to use a 2D array. The print method should print each item in the instance variable via loop techniques.
- 10-05-2011, 08:03 PM #8
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
Re: Matrix
Cant you tell me what to do? I read those manuals and i still dont get it.
I just want to know where i need to set "int [ ] [ ] scores = new int [ 2 ] [ 2 ] ;" And does this make a matrix?
I need only a matrix and it needs to get a print option more not, some more explaination is welcome;)
- 10-05-2011, 08:06 PM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Matrix
Re read those tutorials until you do understand. They are written quite well. I won't give you the answer (but the tutorials will).
- 10-05-2011, 08:36 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Re: Matrix
It's just a matter of local variables versus member variables; it has nothing to do with matrices per se. I agree with Sunde and also tell you to reread the manuals. If we'd give you the answer you'd just copy and paste it without understanding what you did which can be quite dangerous.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Determinant of matrix
By osenna66 in forum New To JavaReplies: 2Last Post: 07-03-2011, 04:57 AM -
Matrix Inverse
By TryingMybestInJava in forum New To JavaReplies: 4Last Post: 11-30-2010, 11:59 PM -
Matrix class
By maz22 in forum New To JavaReplies: 5Last Post: 10-15-2010, 06:53 AM -
help in matrix
By Engineer in forum New To JavaReplies: 7Last Post: 10-06-2010, 01:26 PM -
Help with matrix
By susan in forum New To JavaReplies: 1Last Post: 08-07-2007, 04:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks