博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数组去重
阅读量:4160 次
发布时间:2019-05-26

本文共 935 字,大约阅读时间需要 3 分钟。

package java_se;

import java.util.Arrays;

public class Test05 {

    public static void main(String[] args) {

        int c = 0;
        int[] a = new int[] { 1, 2, 3, 1, 1, 1 };
        RepeatCount rc = new RepeatCount();
        NoRepeat b = new NoRepeat(a.length - rc.repeat(a));
        b.newArry(a);
    }
}

class RepeatCount {

    public int repeat(int[] a) {

        int count = 0;
        for (int i = 0; i < a.length; i++) {
            for (int j = i + 1; j < a.length; j++) {
                // System.out.println(a[i]+","+a[j]);
                if (a[i] == a[j]) {
                    count++;
                    break;
                }
            }

        }

        return count;

    }

}

class NoRepeat {

    int index = 0;
    int t = 0;
    boolean flag = false;

    public NoRepeat(int index) {

        System.out.println(index);
        this.index = index;
    }

    public void newArry(int[] a) {

        int[] b = new int[index];

        for (int i = 0; i < a.length; i++) {

            for (int j = 0; j < b.length; j++) {// 遍历数组a的值是否在b中存在
                if (a[i] == b[j]) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {// 只存放在a中有但是在b中没有 的数据
                b[t++] = a[i];
            }
        }
        System.out.println(Arrays.toString(b));
    }
}
 

转载地址:http://tejxi.baihongyu.com/

你可能感兴趣的文章
sqlite3的helloworld
查看>>
MFC下支持中文的SQLite3封装类使用
查看>>
简单高效的多线程日志类
查看>>
研华USB4711A采集卡高速中断模式采集总结
查看>>
从零起步CMFCToolBar用法详解
查看>>
CMFCRibbonStatusBar用法
查看>>
CMFCControlRendererInfo类的参数
查看>>
史上最详细MFC调用mapX5.02.26步骤(附地图测试GST文件)
查看>>
CMFCShellListCtrl使用方法
查看>>
mapnik的demo运行
查看>>
python支持下的mapnik安装
查看>>
milvus手册
查看>>
多目标跟踪的简单理解
查看>>
Near-Online Multi-target Tracking with Aggregated Local Flow Descriptor
查看>>
Joint Tracking and Segmentation of Multiple Targets
查看>>
Subgraph Decomposition for Multi-Target Tracking
查看>>
JOTS: Joint Online Tracking and Segmentation
查看>>
CDT: Cooperative Detection and Tracking for Tracing Multiple Objects in Video Sequences
查看>>
Improving Multi-frame Data Association with Sparse Representations for Robust Near-online Multi-ob
查看>>
Virtual Worlds as Proxy for Multi-Object Tracking Analysis
查看>>