这几天做题发现一个比较有意思的题[AppleScript] 纯文本查看 复制代码 package Test01;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
/**
*
@ClassName: Lottery.java
@Description:TODO{模拟彩票}
* @author yuzt
@Date :2016年11月21日下午9:23:43
*
*/
public class Lottery {
public static void main(String[] args) {
ArrayList<Integer> lottery = getLottery();
//System.out.println(getLottery());
ArrayList<Integer> yourLottery = getYourLottery();
String prize = getPrize(lottery,yourLottery);
System.out.println("开奖号码是:"+lottery);
System.out.println("您选择的号码为:"+yourLottery);
System.out.println(prize);
}
private static String getPrize(ArrayList<Integer> lottery, ArrayList<Integer> yourLottery) {
int count = 0;
//对比录入的6个数字和原有得数字
for (int i = 0; i < lottery.size(); i++) {
for (int j = 0; j < yourLottery.size(); j++) {
if (lottery.get(i)==yourLottery.get(j)) {
count++;
}
}
}
if (count==3) {
return "恭喜中了三等奖";
}else if (count==4) {
return "恭喜中了二等奖";
}else if (count==5) {
return "恭喜中了一等奖";
}else if (count==6) {
return "恭喜中了特等奖";
}else {
return "非常感谢您为公益事业做出一份贡献";
}
}
private static ArrayList<Integer> getYourLottery() {
//创建一个集合储存输入数字
ArrayList<Integer> arrayList_you = new ArrayList<>();
//键盘录入6个数字
Scanner sc = new Scanner(System.in);
System.out.println("请输入0-15之间的任意6个数字");
while (arrayList_you.size()<6) {
int num = sc.nextInt();
if (num<16 && num>=0) {
arrayList_you.add(num);
}else {
System.out.println("请输入0-15之间的任意数字");
}
}
return arrayList_you;
}
private static ArrayList<Integer> getLottery() {
//创建一个集合
ArrayList<Integer> arrayList = new ArrayList<>();
//存入随机生层的6个数字
Random rd = new Random();
while (arrayList.size()<6) {
int num = rd.nextInt(16);
if (arrayList.contains(num)) {
continue;
}else {
arrayList.add(num);
}
}
return arrayList;
}
}
|