0
 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

4

1 回答 1

1

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

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

喜欢

// 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();
于 2013-04-13T11:35:47.957 回答