diff --git a/Object_Oriented_Programming_With_Java_2/Lab_10_Recursion/Lab_10_Instructions.png b/Object_Oriented_Programming_With_Java_2/Lab_10_Recursion/Lab_10_Instructions.png new file mode 100644 index 0000000..f95716d Binary files /dev/null and b/Object_Oriented_Programming_With_Java_2/Lab_10_Recursion/Lab_10_Instructions.png differ diff --git a/Object_Oriented_Programming_With_Java_2/Lab_10_Recursion/src/Main.java b/Object_Oriented_Programming_With_Java_2/Lab_10_Recursion/src/Main.java new file mode 100644 index 0000000..118f1e4 --- /dev/null +++ b/Object_Oriented_Programming_With_Java_2/Lab_10_Recursion/src/Main.java @@ -0,0 +1,21 @@ +public class Main { + + public static void main(String[] args) { + + double result = m_method(10); + System.out.printf("Result of m_method(%d) is %f \n", 10, result); + } + + public static double m_method(int i) { + double result =- 1; + if (i <= 0) // error case + System.out.println("m_method is not defined for " + i); + else if (i == 1) // base case + result = 1; + else { + System.out.printf("calling m_method(%d) \n", i - 1); + result = m_method(i - 1) + (1.0 / i); // m_method (i - 1) is the recursive call + } + return result; + } +}