所以这里的问题是,当我尝试再次运行它不会做任何事情。 它会运行一次,然后休息。我知道我没有使用currentTimeMillis,没有人知道这里有什么问题。如果你有一些改进我的代码的建议可以随意告诉我,我不擅长编码。 是的,我试图在网上看an but,但我没有找到任何东西。对不起,英文不好!Java:扫描仪行为调试
public static String list(ArrayList<String> lause2) {
Collections.shuffle(lause2);
String pleb = lause2.get(lause2.size() - 1);
return pleb;
}
public static void main(String[] args) throws Exception {
Scanner printer = new Scanner(System.in);
ArrayList<String> lause2 = new ArrayList<>();
ArrayList<Integer> keskiarvo = new ArrayList<>();
long start = System.currentTimeMillis();
long end = start + 10 * 6000;
int laskuri = 0;
boolean go = true;
boolean run = true;
System.out.println("Welcome to Typefaster");
System.out.println("Program will give you random words you will write them as fast as you can for an minute if you fail ones it's over Good luck!");
lause2.add("hello");
//Loads of different lause2.add("random");
lause2.add("vacation");
System.out.println(list(lause2));
while (System.currentTimeMillis() < end) {
laskuri++;
String something = list(lause2);
System.out.println("Write " + something);
String kirjoitus = printer.nextLine();
if (kirjoitus.equals(something)) {
System.out.println("yee");
} else {
break;
}
}
System.out.println("You wrote " + laskuri + " words");
keskiarvo.add(laskuri);
int laskuri2 = 0;
System.out.println("Run again?");
char again = printer.next().charAt(0);
if (again == 'y') {
run = true;
} else if (again == 'n') {
System.out.println("Byebye");
go = false;
}
long start2 = System.currentTimeMillis();
long end2 = start2 + 10*6000;
while (System.currentTimeMillis() < end2 && run) {
laskuri2++;
String something1 = list(lause2);
System.out.println("Write " + something1);
String kirjoitus1 = printer.nextLine();
if (kirjoitus1.equals(something1)) {
System.out.println("yee");
} else {
break;
}
System.out.println("You wrote " + laskuri2 + " words");
keskiarvo.add(laskuri2);
}
}
标题是有点误导,因为你已经确定了错误的源作为代码的漏洞。 – Zabuza