其他分享
首页 > 其他分享> > 怎样查出连续数字中缺失的数字

怎样查出连续数字中缺失的数字

作者:互联网

今天遇到一个问题,是要从1-100中找到缺失的数字,而且是杂序排列,开始的时候确实有点懵,怎么弄啊,后来看了别人的idea,自己动手做了一下,在这里做个记录,大家有更好的意见,请回复啊

 

public class PaiXu {
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        int a[] = {1, 2, 5, 4, 6, 7, 8, 10};
        int b[] = null;
        b = new int[10];
 
        for (int i = 0; i < a.length; i++) {
            b[a[i] - 1] = 1;
        }
        for(int i = 0; i < b.length; i++) {
            if (b[i] == 0) {
                System.out.println("the lost number is " + (i + 1));
            }
        }
    }

 

参考:怎样查出连续数字中缺失的数字

标签:10,数字,int,args,缺失,查出,public
来源: https://www.cnblogs.com/aspirant/p/11663649.html