去除数组中为零的项
来源:互联网 发布:ext ajax 参数类型json 编辑:程序博客网 时间:2024/06/08 00:00
package exercise;
/*
* 去除数组中为零的项*/
public class Demo2 {
public static void main(String[] args) {
int oldArray[] = new int[]{1,2,3,4,0,0,0,0,0,5,6,0,7,0,8,0,9};
int newArray[] = new int[count(oldArray)];
copy(oldArray,newArray);
print(newArray);
}
public static int count(int temp[]){
int n = 0;
for(int x = 0; x < temp.length ; x++ ){
if(temp[x]!=0){
n++;
}
}
return n;
}
public static void copy(int old[],int ne[]){
int n = 0;
for(int x = 0;x < old.length; x++){
if(old[x] != 0){
ne[n] = old[x];
n++;
}
}
}
public static void print(int temp[]){
for(int i=0; i< temp.length;i++){
System.out.print(temp[i]+"、");
}
System.out.println();
}
}
/*
* 去除数组中为零的项*/
public class Demo2 {
public static void main(String[] args) {
int oldArray[] = new int[]{1,2,3,4,0,0,0,0,0,5,6,0,7,0,8,0,9};
int newArray[] = new int[count(oldArray)];
copy(oldArray,newArray);
print(newArray);
}
public static int count(int temp[]){
int n = 0;
for(int x = 0; x < temp.length ; x++ ){
if(temp[x]!=0){
n++;
}
}
return n;
}
public static void copy(int old[],int ne[]){
int n = 0;
for(int x = 0;x < old.length; x++){
if(old[x] != 0){
ne[n] = old[x];
n++;
}
}
}
public static void print(int temp[]){
for(int i=0; i< temp.length;i++){
System.out.print(temp[i]+"、");
}
System.out.println();
}
}
阅读全文
0 0
- 去除数组中为零的项
- cocos2dx 中去除float多余的“零”
- 实训汇编语言设计——删除数组中所有为零的项
- 数组中重复项的去除
- java中数组长度为零和为空的区别
- C++ new大小为零的数组
- for..of语句中如何去除数组中为空的数据
- 简单去除IP地址中多余的零
- 面试题,凑14,将数组中相加为14的数去除,并升序排列
- 求数组中最大和为零的子串 滴滴打车2016笔试题目
- 查找数组中3个相加和为零的元素
- python 去除大文件所有行全为零,所有列全为零的行和列
- 结构体中最后一个数组长度为零
- 3Sum(数组中三个数之和为零)
- sql去除右侧的零
- ABAP中加上前导零、去除前导零的function module
- ABAP中加上前导零、去除前导零的function module
- R中去除为NA的行
- 【PHP学习】一次完整的HTTP请求所经历的7个步骤
- 关于虚拟按键和状态栏控制
- [leetcode]54. Spiral Matrix
- linux挂载大磁盘
- Linux 之 ld.so.conf
- 去除数组中为零的项
- linux有用工具
- 数据科学:以信息为载体的精确体系
- Netty中的ByteBuf
- 在webstorm中配置pug、scss的file watcher及编译路径
- 迷糊的IOException:Java.NET.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
- Nanopc使用USB网卡做简易路由器
- too young 啊
- JavaScript中call和apply的区别