首页 考试吧论坛 Exam8视线 考试商城 网络课程 模拟考试 考友录 实用文档 求职招聘 论文下载
2011中考 | 2011高考 | 2012考研 | 考研培训 | 在职研 | 自学考试 | 成人高考 | 法律硕士 | MBA考试
MPA考试 | 中科院
四六级 | 职称英语 | 商务英语 | 公共英语 | 托福 | 雅思 | 专四专八 | 口译笔译 | 博思 | GRE GMAT
新概念英语 | 成人英语三级 | 申硕英语 | 攻硕英语 | 职称日语 | 日语学习 | 法语 | 德语 | 韩语
计算机等级考试 | 软件水平考试 | 职称计算机 | 微软认证 | 思科认证 | Oracle认证 | Linux认证
华为认证 | Java认证
公务员 | 报关员 | 银行从业资格 | 证券从业资格 | 期货从业资格 | 司法考试 | 法律顾问 | 导游资格
报检员 | 教师资格 | 社会工作者 | 外销员 | 国际商务师 | 跟单员 | 单证员 | 物流师 | 价格鉴证师
人力资源 | 管理咨询师考试 | 秘书资格 | 心理咨询师考试 | 出版专业资格 | 广告师职业水平
驾驶员 | 网络编辑
卫生资格 | 执业医师 | 执业药师 | 执业护士
会计从业资格考试会计证) | 经济师 | 会计职称 | 注册会计师 | 审计师 | 注册税务师
注册资产评估师 | 高级会计师 | ACCA | 统计师 | 精算师 | 理财规划师 | 国际内审师
一级建造师 | 二级建造师 | 造价工程师 | 造价员 | 咨询工程师 | 监理工程师 | 安全工程师
质量工程师 | 物业管理师 | 招标师 | 结构工程师 | 建筑师 | 房地产估价师 | 土地估价师 | 岩土师
设备监理师 | 房地产经纪人 | 投资项目管理师 | 土地登记代理人 | 环境影响评价师 | 环保工程师
城市规划师 | 公路监理师 | 公路造价师 | 安全评价师 | 电气工程师 | 注册测绘师 | 注册计量师
缤纷校园 | 实用文档 | 英语学习 | 作文大全 | 求职招聘 | 论文下载 | 访谈 | 游戏
您现在的位置: 考试吧(Exam8.com) > 计算机等级考试 > 计算机二级 > JAVA > 复习资料 > 正文

2011年计算机等级考试二级Java经典算法大全(18)

来源:考试吧Exam8.com) 2010-10-30 15:48:46 考试吧:中国教育培训第一门户 模拟考场
本文为“计算机等级考试二级Java经典算法大全”,以供广大学员参考使用。更多关于计算机等级考试资料,请访问考试吧计算机等级考试频道(djks.exam8.com)。

  一个随机类

  /*

  * @author talent_marquis<��˺��>

  * Email: talent_marquis@163.com

  * Copyright (C) 2007 talent_marquis<��˺��>

  * All rights reserved.

  */

  package com.dextrys.trilogy.util;

  import java.util.Arrays;

  import org.eclipse.swt.graphics.RGB;

  public class RandomUtil

  {

  /**

  * @param args

  */

  public static void main( String[] args )

  {

  //System.out.println( getRandomNormalString( 8 ) );

  int[] test = getRandomIntWithoutReduplicate( 0, 40, 39 );

  Arrays.sort( test );

  for( int i : test )

  {

  System.out.println( i );

  }

  }

  /**

  * get a integer array filled with random integer without reduplicate [min, max)

  * @param min the minimum value

  * @param max the maximum value

  * @param size the capacity of the array

  * @return a integer array filled with random integer without redupulicate

  */

  public static int[] getRandomIntWithoutReduplicate( int min, int max, int size )

  {

  int[] result = new int[size];

  int arraySize = max - min;

  int[] intArray = new int[arraySize];

  // init intArray

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

  {

  intArray[i] = i + min;

  }

  // get randome interger without reduplicate

  for( int i = 0 ; i < size ; i++ )

  {

  int c = getRandomInt( min, max - i );

  int index = c - min;

  swap( intArray, index, arraySize - 1 - i );

  result[i] = intArray[ arraySize - 1 - i ];

  }

  return result;

  }

  private static void swap( int[] array, int x, int y )

  {

  int temp = array[x];

  array[x] = array[y];

  array[y] = temp;

  }

  /**

  * get a random Integer with the range [min, max)

  * @param min the minimum value

  * @param max the maximum value

  * @return the random Integer value

1 2 3 下一页
  相关推荐:计算机等级考试二级Java编程的三十个基本规则

       计算机等级考试二级Java练习题及答案汇总

文章搜索
版权声明:如果计算机等级考试网所转载内容不慎侵犯了您的权益,请与我们联系800@exam8.com,我们将会及时处理。如转载本计算机等级考试网内容,请注明出处。