Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7725607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:58:51+00:00 2026-06-01T04:58:51+00:00

If we do System.out.printf(%10s, 1); by default, the space characters will be added to

  • 0

If we do System.out.printf("%10s", "1"); by default, the space characters will be added to fill in 10, right? Is there a way to change this?

I know, you can add 0, by specifying 0 before the s, but does printf support anything else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:58:52+00:00Added an answer on June 1, 2026 at 4:58 am

    Nope. Space is hard-coded. Here’s the snippet of java.util.Formatter source even:

    private String justify(String s) {
        if (width == -1)
        return s;
        StringBuilder sb = new StringBuilder();
        boolean pad = f.contains(Flags.LEFT_JUSTIFY);
        int sp = width - s.length();
        if (!pad)
        for (int i = 0; i < sp; i++) sb.append(' ');
        sb.append(s);
        if (pad)
        for (int i = 0; i < sp; i++) sb.append(' ');
        return sb.toString();
    }
    

    If you’re looking to get a different padding you could do a post-format replace or something similar:

    System.out.print(String.format("%10s", "1").replace(' ', '#'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to fix this statement? System.out.printf( 1 | %d | %d | %d\n ,
Here's what I do: double x = 7.0; System.out.printf(%.2f, x); Eclipse gives me this
How can I utilize System.out.print(ln/f) in a way that will allow me to format
Im a PHP-programmer and wonder what this line means. System.out.printf(exp(%.3f) is %.3f%n, x, Math.exp(x))
I was trying to pass a string object to System.out.printf(...) in Java, but I
switch ( choice ) { case '+': System.out.printf( The answer is: %1$.4f.\n, first +
System.out.printf(%7s, a); System.out.printf(%7s, b); System.out.printf(%7s, c); System.out.printf(%7s, d); Just want give for string 7
Possible Duplicate: Advantages and Disadvantages of using System.out.printf(); In a discussion in an online
I was just wondering what were the advantages and disadvantages of using System.out.printf(); We
Is there a way to escape ( or protect ) special characters in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.