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

Popular posts from this blog

How to create React project using command prompt?

How to achieve abstraction?

Interview Question? How to find square of each element in this Array {2,4,5,6,8} using map ?