package englishtest;
import java.util.*;
public class ruko {
private static String[] keys;
public static void main(String[] args) {
Map <String,String> map = new HashMap<>();
map.put("I","我");
map.put("am","是(第一人称)");
map.put("aah","啊");
map.put("hello","你好");
map.put("hi","嗨");
map.put("ooh","嗬");
map.put("goodbye","再见");
map.put("bye-bye","拜拜");
map.put("are","是(第二人称)");
map.put("good","好的");
Scanner scan = new Scanner(System.in);
Random rand = new Random();
System.out.println("欢迎使用外研版英语单词记忆测评系统V1.0.0");
System.out.println("‘1’为三年级");
System.out.println("‘2’为四年级");
System.out.println("‘3’为五年级");
System.out.println("‘4’为六年级");
System.out.print("请输入:");
String a = scan.next();
int fan = 100;
int go = 1;
for (;go <= 100;go += 1) {
if (a.equals(1)) {
//23333
}
}
if (!a.equals("1") && !a.equals("2") && !a.equals("3") && !a.equals("4")) {
if (!a.equals("5") && !a.equals("6") && !a.equals("7") && !a.equals("8")) {
System.out.println("错误!");
}
}
System.out.println("得分;" + fan);
}
}
我想在//23333的地方随机选一个map.put中的数据,输出“(后面的中文)的英文单词是:”,然后让用户输入对应的英文(即前面的英文),然后比较用户的输入和数据,判断是否一样。
但是随机的部分怎么也做不好,有没有人教教我啊?
附:参考资料(网上找的,数据类型有问题):
package pre;
import java.util.*;
public class pre {
public static void main(String[] args) {
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(33, 333);
map.put(123, 1234);
map.put(321, 4321);
map.put(555,5555);
Integer[] keys = map.keySet().toArray(new Integer[0]);
Random random = new Random();
Integer randomKey = keys[random.nextInt(keys.length)];
System.out.println(randomKey);
}
}