2015-10-31 37 views
0

當在Java中如何在一個單獨的行打印:使用3個循環

public class Looping { 

    public static void main(String[] args) { 

     for(int a=1;a<=10;a++){ 
      System.out.println (a); // 
     } 
     for(int a=1;a<=10;a++){ 
      System.out.print (a); // print without spaces 
     } 
     // I need to know what code should go here to start the next loop in a new line 
     for(int a=1;a<=10;a++){ 
      System.out.print (a+ " ");//print with spaces 
     } 
    } 
} 

結果是

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
123456789101 2 3 4 5 6 7 8 9 10 

我想知道如何利用第三循環到新行。像下面一樣

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
12345678910 
1 2 3 4 5 6 7 8 9 10 

回答

0

難道你不能只添加System.out.println();第二次循環後?

+1

上面的兩行都做這個任務:)謝謝:* –

1

只需添加環路之間的空的println

System.out.println (""); 
+1

非常感謝。有用 :) –

1

添加的System.out.println( 「」);在循環之間。它應該工作。