System.out.printf("%s%13s%\n", "TarrifType", "AnnualCost");
System.out.printf("%s%d.%n", "String" 243.08);
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '
at java.util.Formatter.checkText(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at ModelComparison.main(ModelComparison.java:12)
Any idea whats wrong?
What's wrong is the %\n
in the first line. Note that the %
is a special character in a format string that indicates that a format specifier follows. The \n
after the %
is not a valid format specifier.
If you wanted to print a percent sign, then double it in the format string: %%
If you wanted to print a newline, then use %n
, not %\n
.
The problem in your format string is that you mixed two ways of doing newline: %n
and \n
. The former tells the formatter to put a newline in whatever format the platform requires, whereas the latter puts in just a literal newline char. But what you wrote was %\n
, which means you're escaping the newline char, and that's what's blowing up.
You also forgot a comma between "String" and 243.08 in the second call. And btw, %d
formats an integer, so you probably don't want it if you're trying to print 243.08.
Bugs..
System.out.printf("%s%13s\n", "TarrifType", "AnnualCost");
System.out.printf("%s%f\n", "String", 243.08);
http://ideone.com/USOx1
In my case (Android) there was an error in strings.xml
:
<string name="cashback">10% cashback</string>
When I tried to get getString(R.string.cashback)
, I received this exception. To fix it, replace %
with %%
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With