triangle | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

triangle

please tell me how to display the following code: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 ? I deduced like this: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 sample code attached. https://code.sololearn.com/cBQV646qHG2r/?ref=app

6th Jun 2021, 12:22 PM
Best of Sport
Best of Sport - avatar
9 Answers
+ 6
I prefer to use for loop, because for loop looks more clear and readble compare to a while loop. see, this code it will be helpful for you! 👇 https://code.sololearn.com/cT1ZlQ8euDwO/?ref=app
6th Jun 2021, 12:40 PM
Abhiyantā
Abhiyantā - avatar
+ 5
https://www.google.com/amp/s/www.geeksforgeeks.org/print-pattern-using-one-loop-continue-statement/amp/ This site will help you, its not Exact same , but you will get an idea that what to do
6th Jun 2021, 1:11 PM
Abhiyantā
Abhiyantā - avatar
+ 2
I'm a python newbie . this is my code(hope this help you) a=["1"] for i in range(5): print(" ".join(a)) a.append(str(int(a[i])+1))
7th Jun 2021, 1:29 PM
TCorn
TCorn - avatar
+ 1
int j, i = 1; while(i <= 5){ j = 1; while(j <= i){ System.out.print(j+++' '); } System.out.println(); i++; }
6th Jun 2021, 12:57 PM
Solo
Solo - avatar
+ 1
Thank you so much. How can you do it in one cycle?
6th Jun 2021, 12:59 PM
Best of Sport
Best of Sport - avatar
+ 1
In one cycle? Easily 🤣: int i = 1; while(i > 0){ System.out.print( "1\n1 2\n1 2 3\n1 2 3 4\n1 2 3 4 5" ); i--; }
6th Jun 2021, 1:16 PM
Solo
Solo - avatar
+ 1
😆 идеально))
6th Jun 2021, 1:17 PM
Best of Sport
Best of Sport - avatar
+ 1
public class Program { public static void main(String[] args) { int i=1,j=1; while(i<=5) { j=1; while(j<=i) { System.out.print (j+" "); j++; } System.out.println (); i++; } } } //I prefer for loops in case if you like while loops then use this
6th Jun 2021, 5:02 PM
Atul [Inactive]
+ 1
TCorn , it's very cool for a beginner 👏👏👏👏👏👍😉
7th Jun 2021, 3:51 PM
Solo
Solo - avatar