Javaを始めたばかりで、乱数配列を作って時間を計測したいです。System.currentTimeMillis();
私は配列を埋める最初に使用し、その後も同じことを使用しました。次に、ミリ秒をナノ秒に変換したくて使用しlong total=TimeUnit.MILLISECONDS.toNanos(time1);
ましたが、問題が発生しました:
import java.util.*;
import java.util.concurrent.TimeUnit;
public class main {
public static void main(String[] args) {
long time1,time2,time3;
int [] array = new int[10];
Random rand =new Random(100);
time1=System.currentTimeMillis();
for(int i=0;i<array.length;i++){
array[i]=rand.nextInt(100);
}
time2=System.currentTimeMillis()-time1;
long total=TimeUnit.MILLISECONDS.toNanos(time1);
System.out.println("Time is:"+time1
);
}
}
最後に、「Time is:1361703051169;」を取得しました。これは何かがおかしいと思います。