gpt4 book ai didi

java - 打印格式Java

转载 作者:行者123 更新时间:2023-12-01 14:40:44 26 4
gpt4 key购买 nike

 out.append("Line " + (j+1) + ": ");  
System.out.print("Line " + (j+1) + ":");
for (int i = 0; i < lotto.length;i++){
lotto[i] = r.nextInt(45)+1;
out.append(lotto[i] + " ");
System.out.print(lotto[i] + " ");
}

现在打印如下

Line 1: 41 7 38 20 38 39 Line 2: 12 35 5 27 4 33 Line 3: 9 3 10 15 35 2

最佳答案

因为您在打印 Line n 后打印新行

您应该在打印数字的内部 for 之后使用 println

喜欢

// print "Line n"
System.out.print("Line " + (j+1) + ":");

for (int i = 0; i < lotto.length;i++){
lotto[i] = r.nextInt(45)+1;
out.append(lotto[i] + " ");
// Print in the same line the numbers
System.out.print(lotto[i] + " ");
}
// Print the new line
System.out.println();

关于java - 打印格式Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15987323/

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