Left-aligning with printf in Java

后端 未结 1 1808
花落未央
花落未央 2021-02-05 14:52

When I run the program, the factorial value right-aligns. Is there a way to make it left-justified while maintaining the 50 spaces in between?

public class Exerc         


        
相关标签:
1条回答
  • 2021-02-05 15:49

    According to the printf() specification the - symbol left-justifies output.

    System.out.printf("%-50.0f\n",(double)factorial);
    

    source: http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax

    0 讨论(0)
提交回复
热议问题