I have this code:
System.out.println("log n \tn \tn log n\tn^2 \tn^3");
for (long i = 2; i <= 2048; i *= 2) {
System.out.print((int) Math.log(i));
System.out.print('\t');
System.out.print(i);
System.out.print('\t');
System.out.print((int) (i * Math.log(i)));
System.out.print('\t');
System.out.print(i * i);
System.out.print('\t');
System.out.print(i * i *i);
System.out.println();
}
It prints differently in IntelliJ and Command Prompt. See the pictures below:
IJ
cmd
What can I do if I want to see the same results in IJ as it is in cmd?
Thanks!
IntelliJ's command window has a tab width of 4, while the command prompt has a tab width of 8.
You could re-configure IntelliJ to use a tab width of 8, but I wouldn't recommend it.
What can I do if I want to see the same results in IJ as it is in cmd?
Don't use tabs in your output, use spaces. Best achieved using printf
:
System.out.println("log n n n log n n^2 n^3");
for (long i = 2; i <= 2048; i *= 2) {
System.out.printf("%-8d", (int) Math.log(i));
System.out.printf("%-8d", i);
System.out.printf("%-8d", (int) (i * Math.log(i)));
System.out.printf("%-8d", i * i);
System.out.print(i * i * i);
System.out.println();
}
Better yet:
System.out.println("log n n n log n n^2 n^3");
for (long i = 2; i <= 2048; i *= 2) {
System.out.printf("%-7d %-7d %-7d %-7d %d%n",
(int) Math.log(i),
i,
(int) (i * Math.log(i)),
i * i,
i * i * i);
}
The reason for %-7d<space>
instead of %-8d
is that it'll still leave a space between values in case the value takes up more than 7 characters. Sure it'll ruin the nice column layout, but it still allows easier reading of the values.
Output (both IJ and CMD)
log n n n log n n^2 n^3
0 2 1 4 8
1 4 5 16 64
2 8 16 64 512
2 16 44 256 4096
3 32 110 1024 32768
4 64 266 4096 262144
4 128 621 16384 2097152
5 256 1419 65536 16777216
6 512 3194 262144 134217728
6 1024 7097 1048576 1073741824
7 2048 15615 4194304 8589934592