can we convert nested loop in a single loo? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

can we convert nested loop in a single loo?

2nd Sep 2016, 9:41 AM
Shahtaj Jawaid
Shahtaj Jawaid - avatar
6 Answers
+ 1
see example in below public class Program { public static void main(String[] args) { int i; int j; for(i=0,j=0;i<5;i++,j++){ System.out.println("i=" + i + " j=" + j); } } }
2nd Sep 2016, 5:15 PM
Tiger
Tiger - avatar
+ 1
class A { static int i; static { i = 100; System.out.println(1); } static void staticMethod() { System.out.println(i); System.out.println(2); } } public class B { static
2nd Sep 2016, 6:15 PM
Là Anh Nhọ
Là Anh Nhọ - avatar
0
No. you cant becoz when outer for loop runs one time ,inner for loop may run n times ...
2nd Sep 2016, 12:03 PM
Raj Joshi
Raj Joshi - avatar
0
So if there is an example, why not copy and change to the point that you like to have?? this question is not good
17th Oct 2016, 3:30 PM
Finnt730
Finnt730 - avatar
- 1
but there is an example on yahoo in which nested loop is converted into a single loop.....
2nd Sep 2016, 1:44 PM
Shahtaj Jawaid
Shahtaj Jawaid - avatar
- 1
this is not converted from a nested loop Tiger..its a single loop.just used two variables
2nd Sep 2016, 5:40 PM
Raj Joshi
Raj Joshi - avatar