首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印格式Java

打印格式Java
EN

Stack Overflow用户
提问于 2013-04-13 11:33:14
回答 1查看 64关注 0票数 0
代码语言:javascript
复制
 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] + " ");
 }

现在它正在按以下方式打印

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-13 11:35:47

因为您正在打印Line n之后的新行。

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

喜欢

代码语言:javascript
复制
// 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();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15987323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档