您的位置:首页 > 其它

去除连续2个以上的0

2009-08-23 21:56 525 查看
public class Outzero {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] srcArray = {0,0,1,2,0,1,0,0,0,1,0,0,0,0,0,2,0,7,8,9,0,0,1,2,3,4};
int[] destArray = new int[50];
int i=0,j=0,count=0;
for(i=0;i<srcArray.length;){
count = 0;
if(srcArray[i]!=0){
destArray[j++] = srcArray[i];
i++;
}
else{
while(i<srcArray.length&&srcArray[i] == 0){
count++;
i++;
}
//就是凭计数
if(count<2)destArray[j++] = 0;
}
}
for(i=0;i<j;i++){
System.out.print(destArray[i]+" ");

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐