I've searched around and could not find a precedent here for this particular issue. Cited, I've looked at the following questions.
using printf for multiple formats
Formatting using printf and format
Formatting problems using printf in java
Below I'll outline the snippet of my code where I'm having problems. Please keep in mind I'm attempting to understand Efficiency outputs better and am exploring into why certain inputs cause there to be exponential, logarithmic, linear growth, etc etc. Anyways...
for (int i = 0; i < 5; i++) {
time = System.nanoTime();
tl.timeTrial(N);
elapsedTime = (System.nanoTime() - time) / BILLION;
System.out.print(N + "\t");
System.out.printf("%4.3f\t", elapsedTime);
if (i != 0) {
r = elapsedTime / previousTime;
System.out.printf("%3.2\t", r);
k = Math.log(r);
System.out.printf("%3.2\n", k);
}
else {
System.out.print("\n");
}
previousTime = elapsedTime;
N *= 2;
}
From here I'll point out a few things.
System.out.printf("%4.3\t", elapsedTime);
compiles and runs perfectly. However, when I get into the if statement with r and k, I'm getting a run-time error and I do not for the life of me understand why. The error is as follows:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '4'
at java.util.Formatter.checkText(Formatter.java:2579)
at java.util.Formatter.parse(Formatter.java:2565)
at java.util.Formatter.format(Formatter.java:2501)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at TimingLabClient.main(TimingLabClient.java:61)
Thank you for the help. Hopefully I won't get banned for asking a question I couldn't find an answer to again.
Thank you. For those confused about my \t and \ns, it's helping with the output format, which doesn't necessarily have to be perfect.
N Time(sec) R K
8 0.723
16 5.760 7.964 2.075
32 47.098 8.176 2.101
This program is actually going to run for about 7 hours...