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

Answered By
6 Likes
Related Questions
State whether the following statement is True or False :
In a nested loop, break and continue can be used simultaneously.
Write a program in Java to display the following pattern:
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1A 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 find the sum of the following series:
S = 1 + (3/2!) + (5/3!) + (7/4!) + ……. to n