码迷,mamicode.com
首页 > 编程语言 > 详细

Java 随机抽奖

时间:2016-12-26 21:54:59      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:new   抽奖   ati   out   string   stat   class   rgs   generate   

package Third;

import java.util.Scanner;

public class LotteryOdds {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);

System.out.println("How many numbers do you need to draw?");
int k = in.nextInt();

System.out.println("What is the highest number you can draw?");
int n = in.nextInt();

int lotteryOdds = 1;
for(int i =1;i<=k;i++){
lotteryOdds = lotteryOdds*(n-i+1)/i;
System.out.println("Your odds are 1 in "+lotteryOdds+".Good luck");
}
}

}

Java 随机抽奖

标签:new   抽奖   ati   out   string   stat   class   rgs   generate   

原文地址:http://www.cnblogs.com/guo-809264853/p/6223842.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!