性格决定命运,气度影响格局
posts - 20, comments - 18, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

一个String 到 Double 的例子

Posted on 2007-07-28 16:59 尚爱军 阅读(179) 评论(0)  编辑  收藏

public class StrToDou {
 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++) {
   
//System.out.println(sFirst[i]);

   String [] sSecond = sFirst[i].split(",");
    d[i] = new Double[sSecond.length];
   for(int j=0; j<sSecond.length; j++) {
    
//System.out.println(sSecond[j]);

     d[i][j] = Double.parseDouble(sSecond[j]);
    
   }
  }
  
  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();
  }
 } 
}



第一个小程序,作为一个开门红!!!

只有注册用户登录后才能发表评论。


网站导航: