[AppleScript] 纯文本查看 复制代码 package test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
ArrayList<Integer> guessNum = new ArrayList<>();
Scanner sc = new Scanner(System.in);
int index = 1;
while (index <= 7) {
System.out.println("请输入第" + index + "个整数");
int num = sc.nextInt();
guessNum.add(num);
index++;
}
System.out.println("中奖号码为:");
ArrayList<Integer> list = getList();
int count = 0;
for (int i = 0; i < list.size(); i++) {
if (list.get(i) == guessNum.get(i)) {
count++;
}
}
System.out.println("您一共猜对了" + count + "个数字");
}
private static ArrayList<Integer> getList() {
Random rd = new Random();
ArrayList<Integer> list = new ArrayList<>();
while (list.size() <= 5) {
int num = rd.nextInt(33) + 1;
if (!(list.contains(num))) {
list.add(num);
}
}
Collections.sort(list);
int lastNum = rd.nextInt(16) + 1;
list.add(lastNum);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
if (i == 6) {
sb.append(list.get(i));
} else {
sb.append(list.get(i) + ",");
}
}
System.out.println(sb);
return list;
}
}
//不爱写注释,挺简单的,没注释看也应该能看懂
|