Computer Applications
Write a program in Java to display the following pattern:
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1
Java
Java Nested for Loops
81 Likes
Answer
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 5, j = 1; i >= 1; i--, j++) {
for (int k = 1; k <= j; k++)
System.out.print(i + " ");
System.out.println();
}
}
}
Output

Answered By
34 Likes
Related Questions
Write a program in Java to display the following pattern:
1 2 3 4 5
6 7 8 9
10 11 12
13 14
15Using the switch statement, write a menu driven program for the following:
(a) To print the Floyd's triangle:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15(b) To display the following pattern:
I
I C
I C S
I C S EFor an incorrect option, an appropriate error message should be displayed.
A number is said to be Multiple Harshad number, when divided by the sum of its digits, produces another 'Harshad Number'. Write a program to input a number and check whether it is a Multiple Harshad Number or not.
(When a number is divisible by the sum of its digit, it is called 'Harshad Number').
Sample Input: 6804
Hint: 6804 ⇒ 6+8+0+4 = 18 ⇒ 6804/18 = 378
378 ⇒ 3+7+8= 18 ⇒ 378/18 = 21
21 ⇒ 2+1 = 3 ⇒ 21/3 = 7
Sample Output: Multiple Harshad NumberState whether the following statement is True or False :
In a nested loop, break and continue can be used simultaneously.