long start = System.currentTimeMillis();
long m = 0;
System.out.println("Going into the loop");
for (int i = 0; i < 10000000; i++) {
for (int j = 0; j < 1000; j++) {
if (i % 2 == 0 && j % 3 == 0) {
m = i + j;
}
}
}
System.out.println("Out of the loop");
long end = System.currentTimeMillis();
System.out.println("Time : " + (end - start));
System.out.println("m : " + m);
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,“m”的值评估为 10000997,运行时间为 13321。
Going into the loop …Run Code Online (Sandbox Code Playgroud)