I tried to print the below pattern in java
***1***
**2*2**
*3*3*3*
4*4*4*4
like this way
public class Sample {
public static void main(String[] args) {
int m, n;
Scanner s = new Scanner(System.in);
System.out.println("Enter the no of rows");
m = s.nextInt();
System.out.println("Enter the no of columns");
n = s.nextInt();
s.close();
//Printing the number of rows
for (int i = 1; i <= m; i++) {
//printing number of columns
for (int j = n; j > 0; j--) {
//Printing values in the pattern
for (int k = 0; k < j; k++) {
if (k == j / 2)
System.out.print(i);
}
System.out.print("*");
}
System.out.print("\n");
}
}
}
I am facing problem at the logic of finding the positions to print the values in each row. Its asked at my previous interview.