A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 涵門子弟 中级黑马   /  2015-12-4 23:15  /  552 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. package com.tiheima;

  2. import java.util.Arrays;

  3. // 1--10随机生成10个不重复的数字
  4. public class Test_wzs33
  5. {
  6.     public static void main(String[] args)
  7.     {
  8.         int count = 0; // 生成数字数量计数器
  9.         int temp; // 随机生成的数字
  10.         boolean isExist = false; // 判断数字是否存在 true存在,false不存在
  11.         int[] arr = new int[10];
  12.         while (count < 10)
  13.         {
  14.             temp = (int) (Math.random() * 10 + 1);
  15.             for (int i = 0; i < arr.length; i++)
  16.             {
  17.                 if (temp == arr[i])
  18.                 {
  19.                     isExist = true;
  20.                     break;
  21.                 }
  22.                 else
  23.                 {
  24.                     isExist = false;
  25.                 }
  26.             }
  27.             if (!isExist)
  28.             {
  29.                 arr[count] = temp;
  30.                 count++;
  31.             }
  32.         }
  33.         System.out.println(Arrays.toString(arr));
  34.     }
  35. }
复制代码
欢迎大家一起交流!!!!

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马