This repository was archived by the owner on Jul 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursionLab.java
More file actions
74 lines (65 loc) · 2.28 KB
/
RecursionLab.java
File metadata and controls
74 lines (65 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Scanner;
public class RecursionLab {
public RecursionLab() {
boolean runAgain;
Scanner in = new Scanner(System.in);
do {
runAgain = true;
System.out.println("\n---------------------------------");
System.out.println("1 Fibonacci Sequence");
System.out.println("2 Summation");
System.out.println("3 Exponent");
System.out.println("4 Reverse String");
System.out.println("5 Palidrome\n");
System.out.println("Enter any other character to exit");
System.out.println("---------------------------------");
System.out.print(": ");
try {
int input = Integer.parseInt(in.next());
int input2;
int input3;
String strIn;
in.nextLine();
switch (input) {
case 1:
System.out.print("\nNumber of elements to output: ");
input2 = Integer.parseInt(in.nextLine());
System.out.println("Recursive: " + FibonacciSequence.recursiveMethod(input2));
System.out.println("Iterative: " + FibonacciSequence.iterativeMethod(input2));
break;
case 2:
System.out.print("\nSum to #: ");
input2 = Integer.parseInt(in.nextLine());
System.out.println("Recursive: " + Summation.recursiveMethod(input2));
System.out.println("Iterative: " + Summation.iterativeMethod(input2));
break;
case 3:
System.out.print("\nNumber: ");
input2 = Integer.parseInt(in.nextLine());
System.out.print("Power: ");
input3 = Integer.parseInt(in.nextLine());
System.out.println("Recursive: " + Exponent.recursiveMethod(input2, input3));
System.out.println("Iterative: " + Exponent.iterativeMethod(input2, input3));
break;
case 4:
System.out.print("\nString: ");
strIn = in.nextLine();
System.out.println("Recursive: " + ReverseString.recursiveMethod(strIn));
System.out.println("Iterative: " + ReverseString.iterativeMethod(strIn));
break;
case 5:
System.out.print("\nCheck String: ");
strIn = in.nextLine();
System.out.println("Recursive: " + Palidrome.recursiveMethod(strIn));
System.out.println("Iterative: " + Palidrome.iterativeMethod(strIn));
break;
}
} catch(Exception e) {
runAgain = false;
}
} while (runAgain);
}
public static void main(String[] args) {
new RecursionLab();
}
}