+ 1
Java looping
How create code for this out? Input n: 4 Output: * ** *** ****
9 Answers
+ 10
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)
+ 9
â 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 +"*";
+ 9
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 đ
+ 8
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 âș
+ 3
Gaurav Agrawal good point! I changed that đ
+ 3
https://code.sololearn.com/c92YxETutDLE/?ref=app
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.
+ 1
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?
0
Sorry. I need the code for my exam