Not able to pass all the test cases whats wrong wih the code

Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	System.out.println("1");
	System.out.println("1"+"1");
	System.out.println("1"+"1"+"1");
	int i=4;
	while(i<=n) {
		int j=1;
		while(j<=i) {
		
		 if(j==i||j==1)
			System.out.print(1);
		 else if(i%2==1) {
			 System.out.print(1);
		 }
			 
		else
			System.out.print("0");
		j++;
			
		}
		

		
		
			
	
		System.out.println();
		i++;
		
	}
}
	
		}

passed 3 test cases ,1 wrong answer what is wrong

Hii Ritu,
Your logic is wrong because for n = 1 it should print:
1
but your code will print:
1
11
111

that’s why you got 1 test case wrong.

See the no. of characters in each row equals the row number.
The correct logic for this problem is check the row if the row is odd then print 1 equal to row no. of times and if row is even then print 1 first and last and in between print 0.

how to print second row than .i didnt get the logic

Hii Ritu,
Logic for even row is : if the cst == 1 or car == row no. print 1 else print 0

how to solve this still pending

Hi Ritu
What error are you facing now? Can you send the link to the code?

Hi Ritu
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.