入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

数组的基本操作(五)

创建时间:2015-11-25 投稿人: 浏览次数:250

对数组进行删除一个固定数的操作

<span style="font-size:24px;"><span style="font-size:24px;">class ArrayTest {
	public static void main(String[] args) {
        int num = 2;
        int[] arr = { 1, 2, 3, 2, 5, 6, 67 };
        for (int j : delete(arr,num)) {
            System.out.println(j);
        }
    }

public static int[] delete(int[] arr,int a){
	int count=0;
	for (int i=0;i<arr.length ;i++ ) {//判断数组删除后的数组长度
		if (arr[i]!=a) {
			count++;
		}
	}
	int[] tempArr=new int[count];
	for (int i=0,j=0;i<arr.length ;i++ ){
	<span style="white-space:pre">	</span>if (arr[i]!=a) {
			tempArr[j]=arr[i];
			j++;
		
		}
	}
	return tempArr;
}
}</span></span>


声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。