+ 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
9 ответов
+ 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
+ 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
+ 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))
+ 1
int j, i = 1;
while(i <= 5){
j = 1;
while(j <= i){
System.out.print(j+++' ');
}
System.out.println();
i++;
}
+ 1
Thank you so much. How can you do it in one cycle?
+ 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--;
}
+ 1
😆 идеально))
+ 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
+ 1
TCorn , it's very cool for a beginner 👏👏👏👏👏👍😉