+ 1

How to print this pattern form output?

INPUT: abcdefghijk 3 OUTPUT: a *b **c *d e *f **g *h i *j **k

5th Jan 2019, 12:01 PM
Muralikrishnan
Muralikrishnan - avatar
3 Respostas
+ 15
Here is explanation in brief, hope it will make things very clear Muralikrishnan String str = "abcdef..k" int l=str.length(); //we get length of String int n=3; //0,1,2,1,0,1,2,1 & so on .. ● run the outer loop for l number of times [for a ranging from 0 to l-1] ● inside it make a loop for printing number of stars [for b ranging from 0 to a%(3+1)] ● after inside loop over print str.charAt(a) & go to new line using "\n" //make use of %(N+1) , correction by Louis
5th Jan 2019, 2:29 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 11
Hy Muralikrishnan Have a look at my answer in question linked by Anna , ● I have given condition to make series for 3 , so for general number N , ... U can make use of %N to form series like 0,1,2 ...(N-1),...2,1,0 & so on
5th Jan 2019, 2:01 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
5th Jan 2019, 1:35 PM
Anna
Anna - avatar