import java.util.Scanner;
public class NumberTraingle
{
 public static void main(String[] args) 
 {
  int num;
  System.out.print(“Enter number of rows : “);
  Scanner sc = new Scanner(System.in);
  num = sc.nextInt();
  for (int r = 1; r <= num; r++) {
   for (int sp = num – r; sp > 0; sp–) {
    System.out.print(” “);
   }
   for (int c = 1; c <= r; c++) {
    System.out.print(r);
   }
   for (int k = 2; k <= r; k++) {
    System.out.print(r);
   }
   System.out.println();
  }
 }
}


Output:


Enter loop repeat number(rows): 5


         1
       1 2 3
     1 2 3 4 5
   1 2 3 4 5 6 7
 1 2 3 4 5 6 7 8 9


BUILD SUCCESSFUL (total time: 3 seconds)

LEAVE A REPLY

Please enter your comment!
Please enter your name here