To work out how much time is taken to perform an algorithm, I do this in the main method, but it does not print the time as it gets interleaved with System.print.
long startTime = System.currentTimeMillis();
A1.Print(2);
long endTime = System.currentTimeMillis();
System.err.print(endTime - startTime);
and if the class A is this:
public class A{
public void Print(int n){
for(int i = 0; i <=n; i++){
System.out.println(i)
}
}
it prints
0
1
2
and in this line it is the amount of time that is supposed go through that loop, but it simply won't, so it won't print like this:
0
1
2
1
Here the last line or 1 is the millisecond taken for the algorithm. The textbook says you MUST use System.err. and figure out a way to prevent interleaving.