Following Java Program prints the Following Pattern:
0
1 0
0 1 0
1 0 1 0
0 1 0 1 0
import java.util.*;
public class patt5 {
public static void main(String args[]) {
int i, j;
Scanner in = new Scanner(System.in);
System.out.println("Enter the Length of Pattern: ");
int n = in.nextInt();
System.out.println("\nPattern is:");
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
if ((i + j) % 2 == 0) {
System.out.print("0 ");
} else {
System.out.print("1 ");
}
}
System.out.println();
}
}
}
0
1 0
0 1 0
1 0 1 0
0 1 0 1 0
import java.util.*;
public class patt5 {
public static void main(String args[]) {
int i, j;
Scanner in = new Scanner(System.in);
System.out.println("Enter the Length of Pattern: ");
int n = in.nextInt();
System.out.println("\nPattern is:");
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
if ((i + j) % 2 == 0) {
System.out.print("0 ");
} else {
System.out.print("1 ");
}
}
System.out.println();
}
}
}