用java实现矩阵
嗨,我尝试用java实现一个矩阵...我想编写一个方法,它的参数是矩阵的行和列,并且该方法生成矩阵。 我写了这段代码,但它有错误......我的问题是什么?请帮我
public class Table {
int row ;
int column ;
Table (int rows , int columns ){
row = rows;
column = columns;
}
void makeTable(int row , int column){
char[][] ;
c.length = column ;
c[0].length = row ;
}
}
hi i try to implement a matrix by java ... i want to write a method that it's argument is the row and the column of matrix and the method make the matrix.
i write this code but it have error .... what is my problem? please help me
public class Table {
int row ;
int column ;
Table (int rows , int columns ){
row = rows;
column = columns;
}
void makeTable(int row , int column){
char[][] ;
c.length = column ;
c[0].length = row ;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您没有提供具体的错误,但以下是现有代码中的一些错误:
在 Java 中定义多维数组的正确方法是:
您还可以声明一个包含参差不齐的行的数组,每个行都有不同的列长度(或在你的情况下也是一样的,但为什么要把事情复杂化呢?)如下:
You don't provide a specific error, but here are a few in your existing code:
The correct way to define a multidimensional array in Java is:
You can also declare an array with ragged rows each of whom has a different column length (or the same, in your case, but why complicate things?) as follows:
您是否考虑过提供变量名称?或者甚至声明矩阵?
想象:
Have you considered providing variable names? Or even declaring the matrix?
Imagine:
除了存储矩阵的维度(行数和列数)之外,您还需要一个数组或类似的结构来存储数组的内容。这将是类级别(成员变量),
makeTable()
中的char[][] ;
是存储它的错误位置,这会赢无论如何都不会构建,因为您还没有指定名称。As well as storing the dimensions of the matrix (number of rows and columns) you require an array or similar structure to store the contents of the array. This would be a the class level (a member variable),
char[][] ;
you have inmakeTable()
is the wrong place to store that, and this won't build anyway because you haven't specified a name.我知道这可能是家庭作业,因此您需要推出自己的矩阵类。但对于其他人来说,Apache Commons 在其 Math 包中提供了一个运行良好的矩阵库。
http://commons.apache.org /math/api-2.0/org/apache/commons/math/线性/RealMatrix.html
I know this is probably homework and thus you're required to roll your own matrix class. But for others out there Apache Commons has a matrix library in their Math package that works very well.
http://commons.apache.org/math/api-2.0/org/apache/commons/math/linear/RealMatrix.html