Question #269183

You probably have encountered Triangle pattern problems before when you started learning programming. Let’s see how well you do with numbers this time. Try to look at the examples closely and think of an algorithm that replicates the outputs. Go for it!


Input

A single line containing an integer n.

9

Output

The output generated based on the inputted integer n.

1
23
456
789

Expert's answer



package triangle;


import java.util.Scanner;




public class Triangle {


  
    public static void main(String[] args) {
        int k =1;
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i=0; i<n; i++){
            
            for(int j=0; j<=i; j++){
                System.out.print(k);
                k++;
            }
            System.out.println( );
        }
    }
    
}

LATEST TUTORIALS
APPROVED BY CLIENTS