diff --git a/Week 2 Assignment 1/Factorial_W2A1_3.class b/Week 2 Assignment 1/Factorial_W2A1_3.class new file mode 100644 index 0000000..d3ba8bf Binary files /dev/null and b/Week 2 Assignment 1/Factorial_W2A1_3.class differ diff --git a/Week 2 Assignment 1/Factorial_W2A1_3.java b/Week 2 Assignment 1/Factorial_W2A1_3.java new file mode 100644 index 0000000..51a4a39 --- /dev/null +++ b/Week 2 Assignment 1/Factorial_W2A1_3.java @@ -0,0 +1,15 @@ +public class Factorial_W2A1_3 { + static int product = 1; + public static void main(String args[]) { + int num = 4; + System.out.println(recursion(num)); + } + + static int recursion(int num) { + if(num > 0) { + product = product * num; + recursion(num - 1); + } + return product; + } +} \ No newline at end of file diff --git a/Week 2 Assignment 1/Fibonacci_W2A1_1.class b/Week 2 Assignment 1/Fibonacci_W2A1_1.class new file mode 100644 index 0000000..321640c Binary files /dev/null and b/Week 2 Assignment 1/Fibonacci_W2A1_1.class differ diff --git a/Week 2 Assignment 1/Fibonacci_W2A1_1.java b/Week 2 Assignment 1/Fibonacci_W2A1_1.java new file mode 100644 index 0000000..9e7b898 --- /dev/null +++ b/Week 2 Assignment 1/Fibonacci_W2A1_1.java @@ -0,0 +1,18 @@ +public class Fibonacci_W2A1_1 { + static int temp1 = 0, temp2 = 1, temp3 = 0; + public static void main(String arg[]) { + int num = 9; + System.out.print(temp1 + " " + temp2 + " "); + recursion(num); + } + + static void recursion(int num) { + if(num > 0) { + temp3 = temp1 + temp2; + temp1 = temp2; + temp2 = temp3; + System.out.print(temp3 + " "); + recursion(num - 1); + } + } +} \ No newline at end of file diff --git a/Week 2 Assignment 1/Reverse_W2A1_4.class b/Week 2 Assignment 1/Reverse_W2A1_4.class new file mode 100644 index 0000000..8212dc7 Binary files /dev/null and b/Week 2 Assignment 1/Reverse_W2A1_4.class differ diff --git a/Week 2 Assignment 1/Reverse_W2A1_4.java b/Week 2 Assignment 1/Reverse_W2A1_4.java new file mode 100644 index 0000000..74167d9 --- /dev/null +++ b/Week 2 Assignment 1/Reverse_W2A1_4.java @@ -0,0 +1,19 @@ +import java.util.Arrays; + +public class Reverse_W2A1_4 { + static int[] arr = {3,4,6,7,9}; + static int[] reversedArray = new int[arr.length]; + static int counter = 0; + public static void main(String args[]) { + System.out.println(recursion(arr.length)); + } + + static String recursion(int arrLength) { + if(arrLength > 0) { + reversedArray[counter] = arr[(arr.length - 1) - counter]; + counter++; + recursion(arrLength - 1); + } + return Arrays.toString(reversedArray); + } +} \ No newline at end of file diff --git a/Week 2 Assignment 1/SumOFArray_W2A1_2.class b/Week 2 Assignment 1/SumOFArray_W2A1_2.class new file mode 100644 index 0000000..4628b3c Binary files /dev/null and b/Week 2 Assignment 1/SumOFArray_W2A1_2.class differ diff --git a/Week 2 Assignment 1/SumOFArray_W2A1_2.java b/Week 2 Assignment 1/SumOFArray_W2A1_2.java new file mode 100644 index 0000000..15ce919 --- /dev/null +++ b/Week 2 Assignment 1/SumOFArray_W2A1_2.java @@ -0,0 +1,15 @@ +public class SumOFArray_W2A1_2 { + static int sum = 0, i = 0; + static int[] arr = {3,4,2,7,9}; + public static void main(String args[]) { + System.out.println(recursion(arr.length)); + } + static int recursion(int arrLength) { + if(arrLength > 0) { + sum += arr[i]; + i++; + recursion(arrLength - 1); + } + return sum; + } +} \ No newline at end of file