---CHALLENGE OF THE WEEK---
WAP in QBASIC/JAVA to print the following pattern:-
1 2 3 4 5 4 3 2 1
1 2 3 4 A 4 3 2 1
1 2 3 B C D 3 2 1
1 2 E F G H I 2 1
1 I J K L M N O 1
Coding Language:QBASIC OR JAVA
•Spammers maintain social distancing
Answers
CHALLENGE ACCEPTED.
Question:-
Write a program in Java/QBASIC to display the following pattern.
1 2 3 4 5 4 3 2 1
1 2 3 4 A 4 3 2 1
1 2 3 B C D 3 2 1
1 2 E F G H I 2 1
1 I J K L M N O 1
Program:-
This is written in Java.
import java.util.*;
public class Main {
public static void main(String[] args)
{
int n=5;
int a=n, b=n-1, c=0;
char ch='A';
for(int i=1;i<=n;i++)
{
for(int j=1;j<=a;j++)
System.out.print(j+" ");
for(int j=1;j<c;j++)
System.out.print(ch++ + " ");
for(int j=b;j>=1;j--)
System.out.print(j+" ");
c=c+2;
a--;
if(i!=1)
b--;
System.out.println();
}
}
}
Output:-
1 2 3 4 5 4 3 2 1
1 2 3 4 A 4 3 2 1
1 2 3 B C D 3 2 1
1 2 E F G H I 2 1
1 J K L M N O P 1
For versification, check out the attachment.