Computer Applications
Write a program in Java to display the following pattern:
11111
0000
111
00
1
Java
Java Iterative Stmts
6 Likes
Answer
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 5; i> 0; i--) {
for (int j = 1; j <= i; j++) {
if (i % 2 == 0)
System.out.print("0");
else
System.out.print("1");
}
System.out.println();
}
}
}Output

Answered By
1 Like
Related Questions
Define a class to accept a number and check whether it is a SUPERSPY number or not. A number is called SUPERSPY if the sum of the digits equals the number of the digits.
Example1:
Input: 1021 output: SUPERSPY number [SUM OF THE DIGITS = 1+0+2+1 = 4, NUMBER OF DIGITS = 4 ]Example2:
Input: 125 output: Not an SUPERSPY number [1+2+5 is not equal to 3]Write a program in Java to find the Fibonacci series within a range entered by the user.
Sample Input:
Enter the minimum value: 10
Enter the maximum value: 20Sample Output:
13