I am trying to use formatted output and would like to know how would I use %10s in this code
package formattedoutput;
public class FormattedOutput {
public static void main(String[] args) {
double amount;
amount = 43.676;
int spaces;
spaces = 77;
String adding;
adding = "check me out";
System.out.printf( "%1.2f%n", amount );
System.out.println();
System.out.printf("%12d", spaces );
System.out.println();
System.out.printf("%10s", adding );
}
}
From what I did I don't see any difference it says that "The letter "s" at the end of a format specifier can be used with any type of value. It means that the value should be output in its default format, just as it would be in unformatted output. A number, such as the "10" in %10s can be added to specify the (minimum) number of characters. " Am I using it properly ? If so why it says "s" specifier can be used with any type of value ?
toStringmethod.%swith an actualStringparameter. You would do this when you want to pad it with spaces so that it fills a certain width, to make a report look pretty. You might also use this if you have a format string with more than one value to format. You wouldn't normally use just"%s"as the format string, because that is pointless.