【发布时间】:2016-03-11 12:40:45
【问题描述】:
如果我有一个矩阵,例如 3x4,其值为
1 2 3 4
5 6 7 8
9 1 2 3
假设用户想要旋转一列:
输入第 no = 2 列。结果如下:
1 6 3 4
5 1 7 8
9223
然后我想保存这个矩阵,以便我可以用另一种方法旋转它的行:
输入行号 = 2;那么结果将是:
1 6 3 4 1 7 8 5
9 2 2 3
public class Matrix
{
int row;
int column;
int[][] arrays = new int[row][column];
public Matrix(int row, int column)
{
this.row = row;
this.column = column;
this.arrays = new int [row][column];
}
public int getRow()
{
return row;
}
public void setRow(int row)
{
this.row = row;
}
public int getColumn()
{
return column;
}
public void setColumn(int column)
{
this.Column = column;
}
public int getArrays()
{
return arrays[row][column];
}
public void setArray(int row, int column)
{
this.row = row;
this.column = column;
}
public void show()
{
int count = 0;
for(int i = 0; i < this.row; i++)
{
for(int j = 0; j < this.column; j++)
{
if(count < 9)
{
count += 1;
System.out.print(count);
}
else
{
count = 0;
count += 1;
System.out.print(count);
}
}
System.out.println("");
}
}
public void rotateColumn(int column)
{
for(int i = 0; i < this.row; i++)
{
for(int j = 0; j < this.column; j++)
{
if(j == this.column - 1)
{
}
}
}
}
}
我是 Java OOP 的新手,如果有人可以帮助我澄清和指导我的下一步,这将非常有帮助。提前致谢。
【问题讨论】:
-
你知道你的矩阵不是 [[1, 2, 3, 4], [5, 6, 7, 8], [9, 1, 2, 3]] 而是这个 [ [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]??