0% found this document useful (0 votes)
12 views2 pages

Recurs I On With Max

Uploaded by

barsubiasarah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Recurs I On With Max

Uploaded by

barsubiasarah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import javax.swing.

JOptionPane;

public class Recursion {


public static void main(String[] args) {
String[] choices = {"Power", "Factorial", "Fibonacci Sequence", "Min Height
of AVL", "Max Height of AVL", "Exit"};
boolean running = true;

while (running) {
int choice = JOptionPane.showOptionDialog(
null,
"Please choose an operation",
"Recursion Practice",
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
choices,
choices[0]
);

switch (choice) {
case 0: // Power
int base = Integer.parseInt(JOptionPane.showInputDialog("Enter
Base Number"));
int exponent =
Integer.parseInt(JOptionPane.showInputDialog("Enter Exponent Number"));
JOptionPane.showMessageDialog(null, "Result: " +
RecursionMethods.power(base, exponent));
break;

case 1: // Factorial
int number =
Integer.parseInt(JOptionPane.showInputDialog("Enter Factorial Number"));
JOptionPane.showMessageDialog(null, "Result: " +
RecursionMethods.factorial(number));
break;

case 2: // Fibonacci Sequence


int fibonacciNumber =
Integer.parseInt(JOptionPane.showInputDialog("Enter Fibonacci Number"));
JOptionPane.showMessageDialog(null, "Result: " +
RecursionMethods.fibonacci(fibonacciNumber));
break;

case 3: // Min Height of AVL


int nodesForMinHeight =
Integer.parseInt(JOptionPane.showInputDialog("Enter number of nodes for Min Height
AVL"));
JOptionPane.showMessageDialog(null, "Min Height: " +
RecursionMethods.minHeightAVL(nodesForMinHeight));
break;

case 4: // Max Height of AVL


int nodesForMaxHeight =
Integer.parseInt(JOptionPane.showInputDialog("Enter number of nodes for Max Height
AVL"));
JOptionPane.showMessageDialog(null, "Max Height: " +
RecursionMethods.maxHeightAVL(nodesForMaxHeight));
break;
case 5: // Exit
int exit = JOptionPane.showConfirmDialog(null, "Are you sure
you want to exit?", "Exit", JOptionPane.YES_NO_OPTION);
if (exit == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(null, "Closing Program...");
running = false;
}
break;

default:
running = false;
}
}
}
}

You might also like