Java Output Formatting

  • + 2 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