Java缩进打印

结果

我有一个测试代码:

public class Testinh
{
    public static void main(String[] args) {
        String author = "author";
        String title = "title";
        int pages = 0;
        System.out.print('\u000C');
        System.out.printf("Author : %-10s%nTitle : %-10s%nPages : %-10d", author, title, pages);

    }
}

输出为:

Author : author    
Title : title     
Pages : 0 

我如何获得它来打印均等缩进的所有内容,所以我的输出将是:

 Author : author    
 Title :  title     
 Pages :  0

谢谢你。

斯科特·亨特(Scott Hunter)

格式化标签的方式与设置值相同。就像是

System.out.printf("%-8s %-10s%n%-8s %-10s%n%-8s %-10d", "Author :", author, "Title :", title, "Pages :", pages);

或者,您可以只在字符串中添加所需的空格。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章