I need to print this pattern in java using only 2 loops one for the row and the second for the column.
A B C D E
B C D E
C D E
D E
E
D E
C D E
B C D E
A B C D E
What I've tried
public class Main{
public static void main(String[] args) {
int n = 5;
char c = 'A';
for(int i=1; i<=n; i++){
int k=1;
for(int j=1; j<=(n*2)-1; j++){
if(j>=i && j<=((n*2)-i) && k!=0){
System.out.print(c);
k=0;
} else {
System.out.print(" ");
k=1;
c++;
}
}
c = 'A';
System.out.println();
}
}
}
Output: This logic is printing half of the pattern correctly as I'm unable to understand how to built for the second half.