格式化输出从左到右但更复杂 [英] Formatting output left to right but more complex
问题描述
目前我正在研究一些java并遇到了尝试将代码正确格式化为一行的问题。我已将第一组数字分配给存储为String的字符串`string1`,将第二组数字设置为`string2`,将我的最后一组数字设置为`string3`。目前我正在将这些数字输出到txt,这就是`output.print();`正在做的事情。我想要的是第一组数字和最后一组数字之间的等号之间的加号。目前,当我打印出这些数字时,它看起来更像是这样---
Currently I am working on some java and ran across this problem of trying to format my code correctly onto one line. I have set the first group of numbers assigned to the variable stored as a String `string1` the second group of numbers to `string2`and my last group of numbers to `string3`. Currently I am outputting these numbers to a txt so that is what the `output.print();` is doing. What I want is a plus sign in-between the first set of numbers and a equal sign in-between the last set of numbers. Currently when I print out these numbers it looks more like this ---
-20 -32
-12 -9
+ 4 2
2 1
= -16 -30
-10 -8
但是我希望我的输出看起来像这样,他们被分开在一起,当然在数字组之间有一个+和=符号。
However I would like my output to look like this by them being seperated together and of course with a + and = sign between the groups of numbers.
-20 -32 4 2 -16 -30
-12 -9 2 1 -10 -8
output.print(string1 + " + " + string2 + " = " string3);
如果你们能给我一些关于我如何解决这个问题的意见,那就太棒了!谢谢!
我的尝试:
我试过这个
If you guys could give me some input on how I could fix this that would be great! Thank you!
What I have tried:
I have tried this
output.print(string1 + " + " + string2 + " = " string3)
然而这并没有给出输出我希望。
However this did not give the output I was hoping for.
推荐答案
参见 Formatter(Java Platform SE 7) [ ^ ]。
这篇关于格式化输出从左到右但更复杂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!