Java program to generate a Triangle 1 22 333 444

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*Write a program to generate a Triangle.
  eg:
  1
  2 2
  3 3 3
  4 4 4 4 and so on as per user given number */
class Triangle{
	public static void main(String args[]){
		int num = Integer.parseInt(args[0]);
		for(int i=1;i<=num;i++){
			for(int j=1;j<=i;j++){
				System.out.print(" "+i+" ");
			}
			System.out.print("\n");
		}
	}
}

24 Responses to “Java program to generate a Triangle 1 22 333 444”

    • import java.util.*;

      class GFG {
      public static void main (String[] args) {
      Scanner s=new Scanner(System.in);
      int n,i,j,k=0;
      n=s.nextInt();
      for(i=1;i=1;j–)
      {

      System.out.print(j);
      }
      System.out.println(” “);
      }
      }
      }

      Reply

Leave a Reply