79401217

Date: 2025-01-30 21:01:27
Score: 2
Natty:
Report link

Or they could just fix Java.

I'm old C programmer just learning Java (using NetBeans IDE 23).

The textbook I'm using specifies that printf() was put in Java to make it easier to port C code to Java. So my first attempt at using printf instead of println was:

System.out.printf("%*s", 11, myLabel);

which gives a run-time exception trying to process the '*' width specifier.

Every Java reference I found online gives something similar to my code as an example.

No mention of having to kludge it, converting the character set to wide or UTF-8, or writing a fancy method to convert the specified format to a format string that will trick the parser into doing what it should be doing. I'm sorry, the Java printf format parser is broken. They know they are throwing an exception because they found a '*', how hard can it be to just process it as a width specifier? C had it figured out by at least 1988 (See K&R 2nd Edition). It is now 2025. Java needs to fix this.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Contains question mark (0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: C Jones