We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
System.out.printf("%-15s%03d\n",s1,x);
Here "%-15s", "%03d" everyone's doubt why we are using -15, 03
because in that question had clearly mentioned the excepted output "java" and "100" occupy 15 character spaces. '-' left-align the string in the 15-character field.
%s reads the string the s1, and "%03d" %d is used as to read the integer values and occupy 3 digits.0 pad with leading zeros if the number is less than 3 digits.
example : 65 is convert into 065
Java Output Formatting
You are viewing a single comment's thread. Return to all comments →
System.out.printf("%-15s%03d\n",s1,x); Here "%-15s", "%03d" everyone's doubt why we are using -15, 03 because in that question had clearly mentioned the excepted output "java" and "100" occupy 15 character spaces. '-' left-align the string in the 15-character field. %s reads the string the s1, and "%03d" %d is used as to read the integer values and occupy 3 digits.0 pad with leading zeros if the number is less than 3 digits. example : 65 is convert into 065