In printf
, you can't use a %
to represent %
, because a %
means that what follows is a field specifier. If you really want to put a %
in your format, you use a double percent, like so:
System.out.printf("%nThe %s's change is %3.2f%%", oracleStock.name, oracleStock.getChangePercent());
By the way, instead of \n
in printf
, you should use %n
because the latter will print the correct line separator depending on the platform.