0
Guys can you help me out to turn the simple program into a single loop. I want to solve the series 1+22+333+4444+55555
class Patterns { public static void main(String args[]) { int s=0; for(int i =1;i<=5;i++) {int d=0; for(int j=1;j<=i;j++) { d=d*10+i; } s=s+d; } System.out.println(s); } }
8 Respuestas
+ 1
I think you only need one loop here and a series of int -> String -> int conversions. One iterator will be enough for this.
0
I cannot use single loop to get the proper output
0
Is there any way to turn 2 loops into 1 loop
0
Cant understand
0
We have to extract all the numbers
0
Student 31 Yes, but each of them is dependent on one variable and is equal to: int(i) * str(i), right? So you only need one iterable.
0
Thanks for helping
Kuba Siekierzynski & Mireille