How to print this ? HCL L1 interview Question for 3+ experiance
How to print this ?
1
1 2
1 2 3
1 2 3 4
Solution:-
package p3;
public class ABC {
public static void main(String[] args) {
int n=4; //number of Rows
for(int i=1;i<=n;i++) {
for(int j=1;j<=i;j++) {
System.out.print(" "+j);
}
System.out.println(" ");
}
}
}
*******************************************************************
O/P:-
1
1 2
1 2 3
1 2 3 4
Comments
Post a Comment