Computer Applications
Write a program to print following patterns.
(i)
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
(ii)
A
B A
C B A
D C B A
E D C B A
Java
Java Nested for Loops
4 Likes
Answer
public class KboatPattern
{
public static void main(String args[]) {
System.out.println("Pattern 1: ");
for (int i = 5; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " ");
}
System.out.println();
}
System.out.println();
System.out.println("Pattern 2: ");
char ch = 'A';
for (int i = 0; i < 5; i++) {
for (int j = i; j >= 0; j--) {
System.out.print((char)(65 + j) + " ");
}
System.out.println();
}
}
}
Output
![BlueJ output of Write a program to print following patterns. (i) 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 (ii) A B A C B A D C B A E D C B A BlueJ output of Write a program to print following patterns. (i) 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 (ii) A B A C B A D C B A E D C B A](https://cdn1.knowledgeboat.com/img/asp10/2024/1/sp4-p4.jpg)
Answered By
2 Likes
Related Questions
Write the return data type of the following functions.
(a) startsWith( )
(b) log( )
Define a class to declare an array of size 20 of double datatype, accept the elements into the array and perform the following:
Calculate and print the sum of all the elements.
Calculate and print the highest value of the array.
Write a program to input and store integer elements in a double dimensional array of size 4 x 4 and find the sum of all the elements.
7 3 4 5 5 4 6 1 6 9 4 2 3 2 7 5
Sum of all the elements: 73
Write a program to input a number and check whether the number is an automorphic number or not.
An automorphic number is a number whose square "ends" in the same digits as the number itself.
e.g. 52 = 25, 62 = 36, 762 = 5776