import java.util.*;

public class MyTest{
public static void main(String[] args){
Scanner in = new Scanner(System.in); System.out.print("How many numbers do you need to draw? ");
int k = in.nextInt(); System.out.print("What is the highest number you can draw? ");
int n = in.nextInt(); //fill an array with numbers 1 2 3... n
int[] numbers = new int[n];
for(int i = 0; i < numbers.length; i ++)
numbers[i] = i + 1; //draw k numbers and put them into a second array
int[] result = new int[k];
for(int i = 0; i < result.length; i ++){
// make a random index between 0 and n - 1
int r = (int)(Math.random() * n); //pick the element at the random location
result[i] = numbers[r]; //move the last element into the random location\
//ps: I guess the author must consider the Poker when he write down these codes ..........
numbers[r] = numbers[n - 1];
n --;
} //print the sorted array
Arrays.sort(result);
System.out.print("Bet the following combination. It's make you rich!");
for(int r: result)
System.out.println(r);
}
}

最新文章

  1. qq空间返回顶部代码
  2. MySQL 5.7.x 配置教程
  3. 使用 Spring 3 来创建 RESTful Web Services(转)
  4. 对html进行SEO的一点点总结
  5. 关于cocos2d-x精灵加亮及变灰效果
  6. eclipse.ini内存设置
  7. [转]iOS UIAppearance使用详解
  8. 非对称加密算法RSA使用注意事项
  9. mac下利用Breakpad的dump文件进行调试
  10. Java_基础篇(数组排序)
  11. Maven Gradle
  12. volatile(一)
  13. C语言中简单的for循环和浮点型变量
  14. jQuery实现锚点跳转(就一行代码)
  15. [MySQL]修改root密码的4种方法(以windows为例)
  16. 设置dedecms标签 [field:global.autoindex/] 初始值{class递增}
  17. 检测是否为n的因子 Exercise07_06
  18. LINQ不包含列表
  19. hdu1233 继续畅通工程 (最小生成树——并查集)
  20. 转 Linux内存管理原理

热门文章

  1. php socket通信(tcp/udp)
  2. 完整学习git一git设置
  3. App store 如何使用 promo code | app store 打不开精品推荐和排行榜
  4. 20145227《Java程序设计》第1次实验报告
  5. sass初步认识2
  6. 凯撒加密解密(java字母移位)
  7. 【转】SVN服务器搭建--Subversio与TortoiseSVN的配置安装
  8. 【转】学习总结--Cookie &amp; Session总结
  9. Boring count(字符串处理)
  10. Cow Bowling