public class Tickets {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random r = new Random();
List<Integer> list = new ArrayList<Integer>();
List<Integer> list2 = new ArrayList<Integer>();
// 有重复
/*
* for (int i = 0; i < 6; i++) { int num = (r.nextInt(15))+1; list.add(num); }
*/
// 无重复
for (int i = 0; list.size() < 6; i++) {
int ticket = (r.nextInt(15)) + 1;
if (!list.contains(ticket)) {
list.add(ticket);
}
}
for (Integer integer : list) {
System.out.print(integer + " ");
}
System.out.println();
for (int i = 0; i < 6; i++) {
System.out.println("请输入第" + (i + 1) + "个数字(范围是0-15)");
int num = sc.nextInt();
list2.add(num);
}
int num = 0;
System.out.print("您的号码为:");
for (Integer integer : list2) {
for (Integer i : list) {
if (i==integer) {
num++;
}
}
System.out.print(integer+",");
}
// "您的号码为XX,XX,XX,XX,XX,XX,中了X等奖,恭喜您!"或者 "您的号码为XX,XX,XX,XX,XX,XX,没有中奖,!"
switch (num) {
case 3:
System.out.println("中了三等奖");
break;
case 4:
System.out.println("中了二等奖");
break;
case 5:
System.out.println("中了一等奖");
break;
case 6:
System.out.println("中了特等奖");
break;
default:
System.out.println("没中奖");
break;
}
}
}
|