goback add

java例程练习(将string转成double)

2936 点击·0 回帖
灯火互联
楼主

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


喜欢0 评分0