gpt4 book ai didi

java - 打印语句,间距问题。

转载 作者:行者123 更新时间:2023-11-30 10:16:39 24 4
gpt4 key购买 nike

我正在尝试创建一个基于文本的老虎机。然而,当我打印变量“s1”、“s2”或“s3”时,如您所见,一切都发生了变化。我的问题是由 s1 的长度不同引起的。我熟悉 printf 概念,但不确定如何纠正间距问题。

                  ("|=================================|     ____\n" +
"| SLOT MACHINE | [ ]\n" +
"|=================================| / /\n" +
"| | / /\n" +
"| ========================= | / /\n" +
"| | 1 | 2 | 3 | | / /\n" +
"| ========================= | / /\n" +
"| | | | | |===|\n"+
"| | "+s1+"| "+s2+"| "+s3+"| | |\n" +
"| | | | | |===|\n" +
"| ========================= |\n" +
"| |\n" +
"| [Insert Money] |\n" +
"|=================================|" );

输出看起来像这样....

|=================================|     ____
| SLOT MACHINE | [ ]
|=================================| / /
| | / /
| ========================= | / /
| | 1 | 2 | 3 | | / /
| ========================= | / /
| | | | | |===|
| | Apple| Orange| Orange| | |
| | | | | |===|
| ========================= |
| |
| [Insert Money] |
|=================================|

最佳答案

替换为以下内容。应该可以正常工作。

String slotMachine = "|=================================|     ____\n" +
"| SLOT MACHINE | [ ]\n" +
"|=================================| / /\n" +
"| | / /\n" +
"| ========================= | / /\n" +
"| | 1 | 2 | 3 | | / /\n" +
"| ========================= | / /\n" +
"| | | | | |===|\n"+
"| |%7s|%7s|%7s| | |\n" +
"| | | | | |===|\n" +
"| ========================= |\n" +
"| |\n" +
"| [Insert Money] |\n" +
"|=================================|";
System.out.printf(slotMachine, "Apple", "Orange", "Orange");

关于java - 打印语句,间距问题。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49950269/

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