Java looping | Sololearn: Learn to code for FREE!


Java looping

How create code for this out? Input n: 4 Output: * ** *** ****

1/13/2019 5:34:05 PM


9 Answers

New Answer


Denise Roßberg Might that post is deleted now //I will search for previous posts on it(might will be little hard to find such posts bcz many diff. patterns posts)


● 1 loop for rows ● inside it 2 loops : 1 for spaces & 1 for stars //Michal gave a nice understadable code for it ● Just some tip by which U can remove 1 inner loop for stars : stars are following pattern 1, 2, 3, 4 , ... //that is an A.P. So U can do something like : String star =""; //and in every iteration of outer loop print(star += "*"); OR String star = "*"; //and in every iteration of outer loop, the last 2 statement to be executed should be System.our.println(star); star = star +"*";


Hy ZULFITRI There are much more approaches to it, might more efficient ones are also there, U can post a code next time with doubt to get better help 👍


Michal now the general approach is only mentioned in my comment. //I always do this only, whenever I find some increasing A.P. is there ☺



Gaurav Agrawal good point! I changed that 😄

+3 Gaurav Agrawal The same question was asked at 13.01. In the comments of my code you find the old link. Maybe you should know this.


Gaurav Agrawal It was on 9.1. not on 13.1. And if you look at Zulfitri's posts you find another version of this question from 8.1. Could it be a bot?


Sorry. I need the code for my exam