Write a java Program to display following Pattern:
1
0 1
0 1 0
1 0 1 0
public class PatternDisplay {
public static void
main(String[] args) {
int n = 4; //
Number of rows in the pattern
int
numToPrint = (i % 2 == 0) ? 1 : 0;
for (int j =
0; j <= i; j++) {
System.out.print(numToPrint + " ");
numToPrint = 1 - numToPrint;
}
System.out.println();
}
}
}
C:\Program Files\Java\jdk-11.0.17\bin>javac PatternDisplay.java
C:\Program Files\Java\jdk-11.0.17\bin>java PatternDisplay
1
0 1
1 0 1
0 1 0 1
C:\Program Files\Java\jdk-11.0.17\bin>