Testing layout
Diagrams
Combined
flowchart TD
Factorial Subroutine
subgraph factorial
choice -- "1. Factorial" --> inputFactorial["Prompt for number"]
inputFactorial --> callFactorial["Call factorial(n)"]
callFactorial --> checkFactorialNegative{"Is n < 0?"}
checkFactorialNegative -- "Yes" --> factorialError["Throw IllegalArgumentException"]
checkFactorialNegative -- "No" --> initFactorialResult["Set result = 1"]
initFactorialResult --> factorialLoopStart["Initialize i = 1"]
factorialLoopStart --> factorialLoop{"Is i <= n?"}
factorialLoop -- "No" --> factorialEnd["Return result"]
factorialLoop -- "Yes" --> factorialMultiply["Multiply result by i"]
factorialMultiply --> factorialIncrement["Increment i by 1"]
factorialIncrement --> factorialLoop
factorialEnd --> displayFactorialResult["Display Result"]
displayFactorialResult --> menu
end
Fibonacci Subroutine
subgraph fibonacci
choice -- "3. Fibonacci" --> inputFibonacci["Prompt for position"]
inputFibonacci --> callFibonacci["Call fibonacci(n)"]
callFibonacci --> checkFibonacciNegative{"Is n < 0?"}
checkFibonacciNegative -- "Yes" --> fibonacciError["Throw IllegalArgumentException"]
checkFibonacciNegative -- "No" --> checkFibonacciZero{"Is n == 0?"}
checkFibonacciZero -- "Yes" --> fibonacciReturnZero["Return 0"]
checkFibonacciZero -- "No" --> checkFibonacciOne{"Is n == 1?"}
checkFibonacciOne -- "Yes" --> fibonacciReturnOne["Return 1"]
checkFibonacciOne -- "No" --> initFibonacciValues["Set a = 0, b = 1"]
initFibonacciValues --> fibonacciLoopStart["Initialize i = 2"]
fibonacciLoopStart --> fibonacciLoop{"Is i <= n?"}
fibonacciLoop -- "No" --> fibonacciEnd["Return b"]
fibonacciLoop -- "Yes" --> calculateFibonacciC["Set c = a + b"]
calculateFibonacciC --> updateFibonacciValues["Set a = b, b = c"]
updateFibonacciValues --> fibonacciIncrement["Increment i by 1"]
fibonacciIncrement --> fibonacciLoop
fibonacciEnd --> displayFibonacciResult["Display Result"]
displayFibonacciResult --> menu
end
Fib
flowchart TD
subgraph fibonacci
callFibonacci["Call fibonacci(n)"] --> checkFibonacciNegative{"Is n < 0?"}
checkFibonacciNegative -- "Yes" --> fibonacciError["Throw IllegalArgumentException"]
checkFibonacciNegative -- "No" --> checkFibonacciZero{"Is n == 0?"}
checkFibonacciZero -- "Yes" --> fibonacciReturnZero["Return 0"]
checkFibonacciZero -- "No" --> checkFibonacciOne{"Is n == 1?"}
checkFibonacciOne -- "Yes" --> fibonacciReturnOne["Return 1"]
checkFibonacciOne -- "No" --> initFibonacciValues["Set a = 0, b = 1"]
initFibonacciValues --> fibonacciLoopStart["Initialize i = 2"]
fibonacciLoopStart --> fibonacciLoop{"Is i <= n?"}
fibonacciLoop -- "No" --> fibonacciEnd["Return b"]
fibonacciLoop -- "Yes" --> calculateFibonacciC["Set c = a + b"]
calculateFibonacciC --> updateFibonacciValues["Set a = b, b = c"]
updateFibonacciValues --> fibonacciIncrement["Increment i by 1"]
fibonacciIncrement --> fibonacciLoop
end
Prime
flowchart TD
subgraph prime
callPrime["Call isPrime(n)"] --> checkPrimeLessEqual1{"Is n <= 1?"}
checkPrimeLessEqual1 -- "Yes" --> primeReturnFalse["Return False"]
checkPrimeLessEqual1 -- "No" --> primeLoopStart["Initialize i = 2"]
primeLoopStart --> primeLoop{"Is i <= sqrt(n)?"}
primeLoop -- "No" --> primeReturnTrue["Return True"]
primeLoop -- "Yes" --> checkPrimeDivisibility{"Is n % i == 0?"}
checkPrimeDivisibility -- "Yes" --> primeReturnFalse
checkPrimeDivisibility -- "No" --> primeIncrement["Increment i by 1"]
primeIncrement --> primeLoop
end
Factorial
flowchart TD
subgraph factorial
callFactorial["Call factorial(n)"] --> checkFactorialNegative{"Is n < 0?"}
checkFactorialNegative -- "Yes" --> factorialError["Throw IllegalArgumentException"]
checkFactorialNegative -- "No" --> initFactorialResult["Set result = 1"]
initFactorialResult --> factorialLoopStart["Initialize i = 1"]
factorialLoopStart --> factorialLoop{"Is i <= n?"}
factorialLoop -- "No" --> factorialEnd["Return result"]
factorialLoop -- "Yes" --> factorialMultiply["Multiply result by i"]
factorialMultiply --> factorialIncrement["Increment i by 1"]
factorialIncrement --> factorialLoop
end