首页 > 代码库 > 二维数组+字符串split+Double包装类 例题

二维数组+字符串split+Double包装类 例题

将String s = "1,2;3,4,5;6,7,8" 存放在double类型的二维数组中,使得

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

public class IntegerDemo {
	public static void main(String[] args) {
		String s = "1,2;3,4,5;6,7,8";
		double[][] d;
		String[] split = s.split(";");
		d = new double[split.length][];
		for (int i = 0; i < split.length; i++) {
			String[] split2 = split[i].split(",");
			d[i] = new double[split2.length]; 
			for (int j = 0; j < split2.length; j++) {
				d[i][j] = Double.parseDouble((split2[j]));
			}
		}
		for (int i = 0; i < d.length; i++) {
			for (int j = 0; j < d[i].length; j++) {
				System.out.println("d["+i+"]["+j+"]="+d[i][j]);
			}
		}
	}
}


二维数组+字符串split+Double包装类 例题