import java.util.*;
class Demo {
public static void main(String[] args) {
// 创建题库;
Scanner in = new Scanner(System.in);
String[] arrTK={"public","static","void","class","break","true","false","continue"};
String[] arrTK2={"公共的","静态的","无返回的","类","打破","真","假","跳过"};
int[] arr = new int[arrTK.length];
for(int i = 0 ;i<arr.length;i++){
arr[i]= -1;
}
int tIndex=0;
// 出题;
int count = 0;
for(int i =1 ;i <= 8;i++ ){
int index = getT(arrTK2,arr,tIndex);
System.out.println("请写出 "+arrTK2[index]+ " 的单词");
String answer= in.next();
if(answer.equals(arrTK[index])){
count++;
}
tIndex++;
}
System.out.print("您的最终得分是"+(count*20));
for(int i =0 ;i<arr.length;i++){
System.out.print(arr[i]+"\t");
}
}
public static int getT(String[] arrTK2,int[] arr ,int tIndex){
Random r = new Random();
int index=-1;
while(true){
index= r.nextInt(arrTK2.length);
boolean flag =true;
for(int i =0 ; i<arr.length ; i++){
if(arr[i]==index){
flag =false;
}
}
if(flag){
break;
}
}
arr[tIndex]=index;
return index;
}
} |
|