gpt4 book ai didi

java - 一种在终端中居中对齐文本的方法?

转载 作者:太空宇宙 更新时间:2023-11-04 15:21:08 24 4
gpt4 key购买 nike

我正在制作一个基本程序,将文本居中确实有助于组织。我真的不希望这是可能的,但值得一问。

尝试过:

  1. 使用 StringUtils 不起作用,因为 java.lang 没有它,我想。
  2. 用空格填充文本,对于我返回的所有文本来说工作量太大。

有什么想法吗?我知道它是终端,我可能应该使用其他东西来使它看起来更好。

最佳答案

使用System.out.format而不是 System.out.println

此外,您还可以使用 Formatter ,在 Java 文档中:

This class provides support for layout justification and alignment, common formats for numeric, string, and date/time data, and locale-specific output.

关于java - 一种在终端中居中对齐文本的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20370126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com