去掉为0组成新数组

public class Shu2 {

    public static void main(String[] args) {
        int o[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5} ;
        int n[]=new int[o.length];
        //开辟新的数组
        int k=0;
        for(int i=0;i<o.length;i++){
            if(o[i]!=0)    {
                n[k]=o[i];
          System.out.print(n[k]+"\t");      
                k++;
              }
            
        }

    }

}

 

posted @ 2017-04-04 18:55  苏轼的红烧肉  阅读(138)  评论(0编辑  收藏  举报