Given the following program, Convert the recursive version of the method m2 into the iterative version. public class Tes
Posted: Tue Jul 12, 2022 8:16 am
Given the following program, Convert the recursive version ofthe method m2 intothe iterative version.
public class Test {
public static void main(String[ ] args) {
int[ ] a = {10, 20,30, 40, 50};
m2(a, 0,a.length-1);
}
public static void m2(int a[ ], int first, int last) {
if (first <last)
m2(a, first+1, last);
System.out.print(a[first] + " ");
}
}
public class Test {
public static void main(String[ ] args) {
int[ ] a = {10, 20,30, 40, 50};
m2(a, 0,a.length-1);
}
public static void m2(int a[ ], int first, int last) {
if (first <last)
m2(a, first+1, last);
System.out.print(a[first] + " ");
}
}