pyramid sequence in Java
<p>I am new to Java. Just now I'm practing. If I give input as 6, output should be like this:</p>

<pre>
1
2 3
4 5 6
</pre>

<p>Here I'm posting code that I tried:</p>

<pre><code>import java.util.Scanner;

public class Number {
    public static void main(String args[]){

        int n;
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        in.close();
        int k = 1;
        for (int i = 1; i &lt;= n; i++) 
        {
            // k=i;
            for (int j = 1; j &lt;= i; j++)
            {
                System.out.print(" " + k);
                if (n==k)
                {
                    break;
                }
                k++;
            }       
            System.out.println("\n");
        }
    }
}
</code></pre>

<p>If I input n=4,i t show the output as:</p>

<pre>
1

2 3

4

4
</pre>
