ICSE Class 10 Computer Applications
Question 41 of 76
Revising Basic Java Concepts — Question 45
Back to all questions 45
Question Question 26
Write a program to print a pattern as :
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
//
public class KboatPattern
{
public static void main(String args[]) {
int a = 1, b = 0;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
if (j % 2 == 0)
System.out.print(b + " ");
else
System.out.print(a + " ");
}
System.out.println();
}
}
}Output
