Computer Applications
Write a program to display the pattern:
A B C D E
A B C D A
A B C A B
A B A B C
A A B C D
Java
Java String Handling
34 Likes
Answer
public class KboatStringPattern
{
public static void main(String args[]) {
String word = "ABCDE";
int len = word.length();
for (int i = 0; i < len; i++) {
for (int j = 0; j < len - i; j++) {
System.out.print(word.charAt(j));
}
for (int k = 0; k < i; k++) {
System.out.print(word.charAt(k));
}
System.out.println();
}
}
}
Variable Description Table
Program Explanation
Output
Answered By
12 Likes
Related Questions
Write a program to display the pattern:
A
B C
D E F
G H I J
K L M N OWrite a program to generate a triangle or an inverted triangle till n terms based upon the User’s choice of the triangle to be displayed.
Example 1:
Input: Type 1 for a triangle and
Type 2 for an inverted triangle
Enter your choice 1
Enter the number of terms 5
Sample Output:* * * * * * * * * * * * * * *
Example 2:
Input: Type 1 for a triangle and
Type 2 for an inverted triangle
Enter your choice 2
Enter the number of terms 5
Sample Output:A B C D E A B C D A B C A B A
Write a program to generate a triangle or an inverted triangle based upon User’s choice.
Example 1:
Input: Type 1 for a triangle and
Type 2 for an inverted triangle
Enter your choice 1
Enter a word : BLUEJ
Sample Output:
B
L L
U U U
E E E E
J J J J JExample 2:
Input: Type 1 for a triangle and
Type 2 for an inverted triangle
Enter your choice 2
Enter a word : BLUEJ
Sample Output:
B L U E J
B L U E
B L U
B L
BWrite a program to display the pattern:
A B C D E
B C D E
C D E
D E
E