import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int val1 = 1;
int val0 = 0;
for(int row = 1;row<=n;row++){
if(row%2 != 0){
for(int i = 1;i<row;i++){
System.out.print(val1);
}
System.out.println(val1);
}
else{
System.out.print(val1);
int zero = row-2;
for(;zero>0;zero--){
System.out.print(val0);
}
System.out.println(val1);
}
}
}
}
This code is working, but is there a way i can optimize this?