Triangle of height N

Time Limit: 2 sec
Memory Limit: 128000 kB
Problem Statement
Print a right angled triangle of given height N as shown in example.
Input
The input contains a single integer N.

Constraints:-
1 <= N <= 10
Output
Print the Right angled triangle of height N.
Example
Sample Input:-
3

Sample Output:-
*
**
***

Sample Input:-
4

Sample Output:-
*
**
***
****


import java.io.*; // for handling input/output
import java.util.*; // contains Collections 
framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
    public static void main (String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        for(int row=1;row<=a;row++){
            for(int j=1;j<=row;j++){
                System.out.print("*");
            }
            System.out.println();
        }              // Your code here

    }
}

Post a Comment

Previous Post Next Post