100 万回の繰り返しごとにメッセージを出力するループを作成する必要があります。10 秒間 (クロック時間) 実行して、ステートメントがいくつ印刷されるかを確認したいと考えています。
私は今、自分自身を結び目で縛っていると思いますが...
public class OneInAMillion{
public static void main(String []args){
long startTime = System.currentTimeMillis(); //time at start of execution
long endTime = startTime + 10000; //time at end of execution (10000 = 10 seconds)
int count = 1;
while(System.currentTimeMillis() < endTime) { //run this before 10 seconds is up
for (int i = 0; i < count; i++) {
if(i % 1000000 == 0) {
System.out.println("Iteration: " + count++); //print every millionth iteration
}
}
}
System.out.println("Time up!"); //print once loop finishes
}
}