Originally Posted by TheReciever
System.out.printf("The answer for %.3f divided by &d is %.2f." , 5.45, 3, 5.45/3);
The mistake is just the ampersand (&) symbol.
System.out.printf uses string formatting
%s is wildcard for strings
%d is wildcard for integer
and %f is wildcard for floats (decimals etc).
So you are trying to insert three values into the string, 5.45 (float), 3 (integer) and 5.45/3 (float)
Therefor you are using %f (float), %d (digit/ integer) and %f (float)
++ Plus you are adding in precision for the floats (.3 : 3 decimal places & .2 : 2 decimal places)
So your line should be:
System.out.printf("The answer for %.3f divided by %d is %.2f." , 5.45, 3, 5.45/3);
Another example of string formatting would be
String myString = String.format("%s %s %s!", "My", "formatted", "string");
-> would output 'My formatted string!'