日期:2014-05-20  浏览次数:20673 次

矩阵屏幕输入初始化问题...还请帮忙指教
想从屏幕上输入一个矩阵,

例如  

1   2   3
4   5   6

然后怎么定义数组,和怎么用什么办法

能把这个矩阵直接用数组初始化,也就是

S[0][0]=1;S[0][1]=2;     …………

等等,不知道我想表达的意思是否清楚,

有会的前辈还请多多指教  



------解决方案--------------------
1, Define the size, or let user enter the size, n rows and m columns;
2, Create two-dimensional array, size [n][m];
2, Read n lines, each line has m elements, put elements into that array.

------解决方案--------------------
/*
我这里有例子,希望能为您提供一些参考
*/

import java.util.ArrayList;

public class Rect
{
public static void main(String[] args)
{
ArrayList <Integer> a=new ArrayList();

//对数组a进行初始化
for(int i=0;i <6;i++)
{
a.add(new Integer(i+1));
}

//输出数组a
for(int i=0;i <a.size();i++)
{
System.out.print(a.get(i)+ " ");
if((i+1)%3==0)
System.out.println();
}
}
}