Computer Applications
Write a program in Java to display the following pattern:
1
3 1
5 3 1
7 5 3 1
9 7 5 3 1
Java
Java Nested for Loops
122 Likes
Answer
public class KboatPattern
{
public void displayPattern() {
for (int i = 1; i < 10; i = i + 2) {
for (int j = i; j > 0; j = j - 2) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
Variable Description Table
Program Explanation
Output
Answered By
53 Likes
Related Questions
Write a program to input a number and check whether it is 'Magic Number' or not. Display the message accordingly.
A number is said to be a magic number if the eventual sum of digits of the number is one.
Sample Input : 55
Then, 5 + 5 = 10, 1 + 0 = 1
Sample Output: Hence, 55 is a Magic Number.
Similarly, 289 is a Magic Number.Write a program in Java to display the following pattern:
1 2 3 4 5
6 7 8 9
10 11 12
13 14
15Write a program in Java to display the following pattern:
15 14 13 12 11
10 9 8 7
6 5 4
3 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 Number