Reputation: 109
I'm required (by my teacher) to use Java 1.4 and I need to use a Formatter to format my output into a table. Is there any other way I can do this? Right now, I have it looking like this:
System.out.printf("%-15s %-15s %-15s %n", "Name", "Day", "Time");
for (int i = 0; i < show.size(); i++){
System.out.printf("%-15s %-15s %-4d %n", ((showInfo)show.get(i)).name, ((showInfo)show.get(i)).day, ((showInfo)show.get(i)).time);
And it works on the IDE, but when I run it in my command prompt (1.4) it gives me errors. Is there any other way to make the table?
Any help would be great! Thanks in advance!
Upvotes: 0
Views: 96
Reputation: 108954
Java 1.4 doesn't have PrintStream.printf()
, it was added in Java 1.5.
You need to make sure that you actually use Java 1.4 in your IDE to be sure that you only use methods that exist in that Java version.
It has been a while since I used Java 1.4, but you have to do the formatting yourself, eg by left padding the string if it is too short.
BTW: Tell your teacher to get with the times, Java 1.4 was released in 2002, Java 5 (1.5) in 2004, Java 6 (1.6) in 2006 and Java 7 (1.7) in 2011. What use is it to constrain students by using outdated and insecure(!) versions of Java?
Upvotes: 1