62,614
社区成员
发帖
与我相关
我的任务
分享
/*
String s = "1,2;3,4,5;6,7,8";
分成
对应的数组
d[0, 0] = 1.0; d[0, 1] = 2.0;
d[1, 0] = 3.0; d[1, 1] = 4.0; d[1, 2] = 5.0;
d[2, 0] = 6.0; d[2, 1] = 7.0; d[2, 2] = 8.0;
*/
String s = "1,2;3,4,5;6,7,8";
String[] spt = s.split(";");
Double[][] dou;
dou = new Double[spt.length][];
for( int i = 0; i < spt.length; i++ ) {
String[] str = spt[i].split(",");
dou[i] = new Double[str.length];
for(int j = 0; j < str.length; j++ ) {
dou[i][j] = Double.valueOf(str[j]);
}
}
for( int i = 0; i < spt.length; i++ ) {
for( int j = 0; j < dou[i].length; j++ ) {
System.out.print(dou[i][j] + " ");
}
System.out.println();
}
/*
String s = "1,2;3,4,5;6,7,8";
分成
对应的数组
d[0, 0] = 1.0; d[0, 1] = 2.0;
d[1, 0] = 3.0; d[1, 1] = 4.0; d[1, 2] = 5.0;
d[2, 0] = 6.0; d[2, 1] = 7.0; d[2, 2] = 8.0;
*/
String s = "1,2;3,4,5;6,7,8";
String[] spt = s.split(";");
double[][] dou;
dou = new double[spt.length][];
for( int i = 0; i < spt.length; i++ ) {
String[] str = spt[i].split(",");
dou[i] = new double[str.length];
for(int j = 0; j < str.length; j++ ) {
dou[i][j] = Double.parseDouble(str[j]);
}
}
for( int i = 0; i < spt.length; i++ ) {
for( int j = 0; j < dou[i].length; j++ ) {
System.out.print(dou[i][j] + " ");
}
System.out.println();
}