Computer Applications
Write a program in Java to display the following pattern:
1 7 12 16 19 21
2 8 13 17 20
3 9 14 18
4 10 15
5 11
6
Java
Java Nested for Loops
10 Likes
Answer
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 1, a = 6; i <= 6; i++, a--) {
int c = 7;
for (int j = i, b = 1; b <= a; j += c, b++) {
System.out.print(j + " ");
c--;
}
System.out.println();
}
}
}
Output

Answered By
4 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
15A 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 NumberWrite a program in Java to display the following pattern:
AAAAA
BBBB
CCC
DD
EWrite a program in Java to find the sum of the following series:
S = 1 + (3/2!) + (5/3!) + (7/4!) + ……. to n