Please help me print this pattern | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please help me print this pattern

e ded cdedc bcdedcb abcdedcba https://code.sololearn.com/cXB0fJU4zT4N/?ref=app

13th Nov 2020, 11:03 AM
Neil
Neil - avatar
5 Answers
+ 2
Input the letter you want to start. So input "e" or "E" for your example. https://code.sololearn.com/cJnD78Bgn2sP/?ref=app
13th Nov 2020, 11:58 AM
Coding Cat
Coding Cat - avatar
+ 4
System.out.println("e"); System.out.println("ded"); System.out.println("cdedc"); System.out.println("bcdedcb"); System.out.println("abcdedcba"); There you go. Similar to your attempt.
13th Nov 2020, 11:07 AM
Avinesh
Avinesh - avatar
+ 2
I don't know java but I can tell you the Idea and then you implement it in java language. I) create an array with all the letters. II) the outer for runs from i=4 (wich is the array position of "e") till i>=0. Each lap of the outer for represents a line of characters. III) the inner for is what actually print the characters in each line. You need two inner for, the first running from j=4-i until j<i (++i). And in each lap it prints: arrayOfLetters[ j ]; The second loop running from j=i until j>=4-i (--j). And in each lap it prints: arrayOfLetters[ j ]; then you go on a new line a start another lap of the outer for. EDIT: just to make the idea clear. You need two inner for. the first printing letters in ascending order and the second in descending order. The first need to start with an index that is at a certain distance from "i" (the index of the outer for, counting the current row) and nees to end at "i". The second needs to start from "i" and go back till a certain distance from i
13th Nov 2020, 11:39 AM
Davide
Davide - avatar
+ 2
Coding CAT Thank you so much and Davide also thank you for your explanation. I can not upvote any answer cause my account isn't activated yet.
13th Nov 2020, 2:57 PM
Neil
Neil - avatar
0
By using for loop
13th Nov 2020, 11:07 AM
Neil
Neil - avatar