首页 > 其他分享 >MyTest3

MyTest3

时间:2024-11-10 09:44:33浏览次数:3  
标签:count int ArrayList al value 2000 MyTest3

package com.shrimpking.t16;

import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2024/11/9 20:54
 */
public class MyTest3
{
    public static void main(String[] args)
    {
        ArrayList<Integer> al = new ArrayList<>();
        while (al.size() < 1000){
            int value = (int)(Math.random() * 2000); //2000以内随机一个数
            boolean b = true;
            for (Integer v : al)
            {
                if (value == v){
                    b = false; //已经有个数,就标记
                    break;
                }
            }
            if (b){
                al.add(value); //不重复,就添加
            }
        }

        int count = 0;
        for (Integer v : al)
        {
            System.out.printf("%-4d\t",v);
            count++;
            if (count > 10){
                System.out.println(); //换行
                count = 0;
            }
        }
    }
}

标签:count,int,ArrayList,al,value,2000,MyTest3
From: https://blog.csdn.net/modern358/article/details/143651197

相关文章