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");
		}
	}
}
surajk

15 thoughts on “Java program to generate a Triangle 1 22 333 444

  1. only logic
    for(int i=1;i<=5;i++)
    {
    for(int j=1;j<=i;j++)
    {
    Systam.out.print(i);
    }
    Systam.out.print("\n");
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in