去除连续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]+" ");
}
}
}
/**
* @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]+" ");
}
}
}
相关文章推荐
- fpc : 连续2个以上的空格替换成1个空格
- 去除一个字符串的开头和结束部分的空格,中间有连续的两个或两个以上的空格,则保留一个空格
- 求一些随机数中连续的数(2个或者2个以上)的和
- 移除字符串中连续2个0 (连续3个或3个以上不需要移除)
- 某公司笔试题:编程实现去除字符串中连续出现一次以上的空格。
- 输入几个分数,去除最高2个,最低2个,求和以后再求平均分(5个以上)
- iOS调用perform selector超过2个参数以上的方法
- 实现简易字符串压缩算法:由字母a-z或者A-Z组成,将其中连续出现2次以上(含2次)的字母转换为字母和出现次数,
- 客户端C和服务器S之间建立了一个TCP连接,TCP最大段长度为1KB,客户端C当前的拥塞窗口是16KB,向服务器S连续发送2个最大段之后,成功收到服务器S发送的第一段的确认段,确认段中通告的接受窗口大
- 编码实现环状单向链表(尾指针直接指向头指针,中间没有空节点),去除连续的重复元素的操作
- [腾讯面试]有1到10w这10w个数,去除2个并打乱次序,如何找出那两个数
- 字符串消除连续出现3次及以上的字符
- 谷歌笔试题-去除连续空格并翻转字符串
- JS密码校验规则前台验证(不能连续字符(如123、abc)连续3位或3位以上)(不能相同字符(如111、aaa)连续3位或3位以上)
- T-SQL查询:连续输出2个日期间的日期
- C#如何调用其他.config配置文件,就是2个乃至3个以上的config文件
- 查询出有2个用户以上的角色信息
- 如果2个数组重复的值,找出重复的值,在其中一个数组中去除
- 用NuGet管理程序包时,如果解决方案目录下的packages文件夹中某一个程序包存在2个以上的版本,则会提示错误
- 有1到10w这10w个数,去除2个并打乱次序,如何找出那两个数