Here is the code that let you print the triangle.
- import java.util.Scanner;
- class Triangle
- {
- public static void main(String args[])
- {
- int n, c, d;
- Scanner in = new Scanner(System.in);
- System.out.println("Enter the number of rows of triangle you want");
- n = in.nextInt();
- System.out.println("Here is your triangle :-");
- for ( c = 1 ; c <= n ; c++ )
- {
- for ( d = 1 ; d <= c ; d++ )
- {
- System.out.print("*"+" ");
- }
- System.out.println();
- }
- }
- }
Thank you, keep learning and sharing.