Manmohan loves patterns

Please Please tell me why this code is not passing the testcases given in problem manmohan loves patters-II

import java.util.*;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = 5;
System.out.println(“1”);
for(int i=1;i<n;i++) {
System.out.print(i);
for(int j=0;j<i-1;j++) {
System.out.print(“0”);
}
System.out.print(i);
System.out.println();
}
}
}

i dont know how the indentation changed automatically. Apologies.

Hii Mudit,
First you don’t have to fix value of n, you have to take the value of n from user. And in this question the correct logic is
If the row is equal to 1 then print 1
Else if column is 1 or column is equal to nst then print row - 1 , else print 0 where nst is the total no. of column in each row

Hi Mudit, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.

I didnt got the logic which you are telling me. I have changed the code and taken input from user and it started working fine. Can you please explain the logic and if possible please provide the code also.

Hi Mudit,
See for input 5, output is:
1
11
202
3003
40004

when we start looking the pattern from row no. 2 then you can observe that first and last character in every row is row no. -1 and in between character are 0 and total no. of characters in each row equals to row number. And row no. 1 always contain 1.