Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 各位,俺来扔个砖头——给出我的实现方法 [Re:hxu0]
铁针





发贴: 90
积分: 1
于 2005-04-11 14:35 user profilesend a private message to usersend email to 铁针search all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
源代码如下:
/**
* @author Qingyi Wu
*/
public final class ArrayChecker {

public static final int NUM_ARRAY[] = {23, 67, 212343, 422, 1239, 0, 122332};

/**
* Core function is here! A new boolean array is created to indicate the position
* in the number array where the element is not fixed the condition
* @param limit any element in the parameter array whose value is <= limit will be ingnored
* @param array numbers array which you want to do filter for
* @return the number array that has filtered
*/
public static int[] check(int limit, final int[] array) {

if (array == null || array.length == 0)
throw new IllegalArgumentException("Parameter array should not be NULL");

//position flags
boolean[] boolArray = new boolean[array.length];

//Obtain the fixed length for new array
int fixedCounter = 0;
for (int i = 0; i < array.length; i++) {

if (array[i] > limit) {
boolArray[i] = !boolArray[i];
fixedCounter ++;
}
}

//fill the new array
int[] newArray = new int[fixedCounter];
int insertPoint = 0;
for (int i = 0; i < boolArray.length; i++) {

if (boolArray[i]) {
newArray[insertPoint] = array[i];
insertPoint++; //point to next position
}
}
return newArray;
}

/*Only for testing*/
public static void main(String[] args) {
int limitValue = Integer.parseInt(args[0]);

int[] filterdArray = ArrayChecker.check(limitValue, ArrayChecker.NUM_ARRAY);
for (int i = 0; i < filterdArray.length; i++)
System.out.print(filterdArray[i] + "\t");
}
}





话题树型展开
人气 标题 作者 字数 发贴时间
3462 请问一个关于数组的问题 hxu0 141 2005-04-09 10:35
2607 Re:请问一个关于数组的问题 PrimeJava 34 2005-04-09 15:33
2673 Re:请问一个关于数组的问题 hxu0 126 2005-04-09 16:13
3113 各位,俺来扔个砖头——给出我的实现方法 铁针 1833 2005-04-11 14:35

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923