This is the right align triangle and it creates based on user input.


Program Code :

import java.util.Scanner;
public class Triangle{
public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
System.out.print("Enter the number of star = ");
int n=scn.nextInt();
for (int i = 1; i <=n; i++) {
for (int j = n-i; j >=1; j--) {
System.out.print(" ");
}
for (int k = 1; k <=i; k++) {
System.out.print("*");
}
System.out.println("");
}
}
}


Output :

 Enter the number of star = 10
                  *
                **
              ***
            ****
          *****
        ******
      *******
    ********
  *********
**********


 
Top