Though my output is right but it is showing testcase wrong answer while submitting the code


my code is

Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
int row=1;
while(row<=n) {
for(int i=1;i<=row;i++) {
if(row<=n/2) {
System.out.print(“1”);

			}
			else {
				if(i>1&&i<row) {
					System.out.print("0");
			}
				else {
					int row1=row-1;
					System.out.print(row1);
				}
			}
			
		}
		System.out.println();
		row=row+1;
	}

}

}

Hi Shivendra

For input 1, output should be 1 whereas your code gives the output 0.

then what changes can we make to print correct output

Hi Shivendra

The best approach for solving this question is to first try to make the shape and assume that the numbers are not present.
For the time being, assume that there are no numbers present in the pattern and replace them with stars. Once you’ve attained the right shape, then try to add numbers in that pattern.

Hint: For each row, numbers are printed only in the first and the last coloumn.