This is challenge number 5 for fundamentals and patterns. Can you please check what wrong m i doing here

package Challenge;

import java.util.Scanner;

public class Chal6 {

public static void main(String[] args) {
	// let i be rows and j be column
	// if odd row number print 1
	// if even row number first and last column should have 1 rest zero
	Scanner scn = new Scanner(System.in);
	int row = scn.nextInt();
	for (int i = 1; i <= row; i++) {
		
		for (int j =1; j<=i;j++) {
			if(i%2==0) {
				if(j==1&&j==i) {
					System.out.print("1");
				}else {
					System.out.print("0");
				}
				
			}else {
				System.out.print("1");
			}
		}
		System.out.println();
		
			
	}
	}	

}

Hey @kalindiyadav5
code is fine just a change
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
	// let i be rows and j be column
	// if odd row number print 1
	// if even row number first and last column should have 1 rest zero
	Scanner scn = new Scanner(System.in);
	int row = scn.nextInt();
	for (int i = 1; i <= row; i++) {

		for (int j = 1; j <= i; j++) {
			if (i % 2 == 0) {

// mera change
if (j == 1 || j == i) {
System.out.print(“1”);
} else {
System.out.print(“0”);
}

			} else {
				System.out.print("1");
			}
		}
		System.out.println();

	}
}

}

1 Like