diff --git a/Semester 3/Assignments/RecursionDemo/pom.xml b/Semester 3/Assignments/RecursionDemo/pom.xml new file mode 100644 index 0000000..4f49854 --- /dev/null +++ b/Semester 3/Assignments/RecursionDemo/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + edu.slcc.asdv.caleb + RecursionDemo + 1.0-SNAPSHOT + jar + + UTF-8 + 20 + 20 + edu.slcc.asdv.caleb.recursiondemo.RecursionDemo + + \ No newline at end of file diff --git a/Semester 3/Assignments/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java b/Semester 3/Assignments/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java new file mode 100644 index 0000000..352c17a --- /dev/null +++ b/Semester 3/Assignments/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java @@ -0,0 +1,84 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ +package edu.slcc.asdv.caleb.recursiondemo; + +/** + * + * @author caleb + */ +public class RecursionDemo { + + static void printNTimes(int nTimes, String message) + { + for (int i = 0; i < nTimes; ++i) { + System.out.println(message); + } + } + + public static boolean isPalendrome(String s) + { + String backwards = ""; + for (int i = s.length() - 1; i >= 0; i--) { + backwards += s.charAt(i); + } + return s.equals(backwards); + } + + public static long fib(int n) + { + if (n == 1 || n == 2) { + return 1; + } + System.out.println(n); + return fib(n - 1) + fib(n - 2); + } + + static void printNTimesRecursion(int nTimes, String message) + { + if (nTimes == 0) { + return; + } + System.out.println(message); + printNTimesRecursion(--nTimes, message); + } + + public static boolean isPalendromeRecursion(String s) { + if (s.length() == 0 || s.length() == 1) { + return true; + } else if (s.charAt(0) != s.charAt(s.length() - 1)) { + return false; + } + return isPalendromeRecursion(s.substring(1, s.length() - 1)); + } + + public static long factorial(int n) + { + long fact; + if (n == 1) { + return 1; + } + fact = n * factorial(n - 1); + return fact; + } + + public static void printArrayRecursively(int[] arr, int index) { + if (index == arr.length) { + return; + } else { + System.out.print(arr[index] + " "); + printArrayRecursively(arr, index+1); + } + } + + public static void main(String[] args) + { + System.out.println(factorial(20)); + printNTimesRecursion(1, "Hello Recursion"); + //System.out.println(fib(10)); + System.out.println(isPalendrome("detartrated")); + System.out.println(isPalendromeRecursion("detartrated")); + int[] arr = {2, 3, 5, 6, 7, 8, 10, 32, 64, 128}; + printArrayRecursively(arr, 0); + } +} diff --git a/Semester 3/Assignments/RecursionDemo/target/RecursionDemo-1.0-SNAPSHOT.jar b/Semester 3/Assignments/RecursionDemo/target/RecursionDemo-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..c1fdbd2 Binary files /dev/null and b/Semester 3/Assignments/RecursionDemo/target/RecursionDemo-1.0-SNAPSHOT.jar differ diff --git a/Semester 3/Assignments/RecursionDemo/target/classes/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.class b/Semester 3/Assignments/RecursionDemo/target/classes/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.class new file mode 100644 index 0000000..45f3b40 Binary files /dev/null and b/Semester 3/Assignments/RecursionDemo/target/classes/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.class differ diff --git a/Semester 3/Assignments/RecursionDemo/target/maven-archiver/pom.properties b/Semester 3/Assignments/RecursionDemo/target/maven-archiver/pom.properties new file mode 100644 index 0000000..7e807e9 --- /dev/null +++ b/Semester 3/Assignments/RecursionDemo/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=RecursionDemo +groupId=edu.slcc.asdv.caleb +version=1.0-SNAPSHOT diff --git a/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..b53fde3 --- /dev/null +++ b/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.class diff --git a/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..7972ded --- /dev/null +++ b/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/caleb/ASDV-WebDev/Semester 2/RecursionDemo/src/main/java/edu/slcc/asdv/caleb/recursiondemo/RecursionDemo.java diff --git a/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/Semester 3/Assignments/RecursionDemo/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29