(BlueJ,Java) Program to Generate a Triangle.
Code:
Code:
/*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(int num){
for(int i=1;i<=num;i++){
for(int j=1;j<=i;j++){
System.out.print(" "+i+" ");
}
System.out.print("\n");
}
}
}
Comment below for your Query and Feedback... :)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(int num){
for(int i=1;i<=num;i++){
for(int j=1;j<=i;j++){
System.out.print(" "+i+" ");
}
System.out.print("\n");
}
}
}
0 comments:
Confused? Feel free to ask
Post a Comment