+ 1
How to make this using looping in java
12345 2345 345 45 5 please đ help me.
1 Answer
+ 2
There could be a more optimal way with a single for loop, but here's an easy method:
Use two for loops.
Both are incremented by 1 each itteration, one is nested inside the other.
Print the value of the inside for loop's variable.
Print onto the next line when the inside loop is finished.
The trick is that the inside for loops variable will not be equal to 1 when the loop starts. It will be equal to whatever itteration the outer loop is on. That way you only go from 1 to 5 initially, then next loop will go from 2 to 5. Then 3 to 5. etc..
Oh, also the loops will both keep going until their variables are equal to 5. đ
The hardest part IMO will be the spacing.
Perhaps add more spaces based on the outer loops variable - 1.
- 1 so there's no space on the first line.
Just so you're not confused, when I say "for loop's variable" I'm referring to 'i' in this example:
for(int i = 0; i < 100; i++){}