鱼欲遇雨:每日都学习一点,持之以恒,天道酬勤!不能用电脑时,提前补上!(2012.8.29)
编写一个方法,返回一个double型二维数组,数组中的元素通过解析字符串参数获得。
// ArrayParser.java
public class ArrayParser {
public static void main(String[] args) {
double[][] d;
String s = "1,2;3,4,5;6,7,8";
String[] sFirst = s.split(";");
d = new double[sFirst.length][];
for(int i = 0; i < sFirst.length; i ++) {
String[] sSecond = sFirst[i].split(",");
//System.out.println(sFirst[i]);
for(int j = 0; j < sSecond.length; j ++) {
//System.out.println(sSecond[j]);
d[i] = new double[sSecond.length];
d[i][j] = Double.parseDouble(sSecond[j]);
System.out.print(d[i][j] + " ");
}
System.out.println();
}
/*
for(int i = 0; i < d.length; i ++) {
for(int j = 0; j < d[i].length; j ++){
System.out.print(d[i][j] + " ");
}
System.out.println();
}
*/
}
}