From 792bd043deac03b4e72b05a3ee2f9c96ab89a3dc Mon Sep 17 00:00:00 2001 From: Steve Ham Date: Mon, 15 Oct 2018 17:30:05 -0600 Subject: [PATCH] Scala version in math/fibonacci --- math/fibonacci/Scala/fibonacci.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 math/fibonacci/Scala/fibonacci.scala diff --git a/math/fibonacci/Scala/fibonacci.scala b/math/fibonacci/Scala/fibonacci.scala new file mode 100644 index 0000000..91d1560 --- /dev/null +++ b/math/fibonacci/Scala/fibonacci.scala @@ -0,0 +1,16 @@ +object fibonacci { + def main(args: Array[String]): Unit = { + print("Input the nth fibonacci number you'd like to compute: ") + val x: Int = scala.io.StdIn.readLine.toInt + println(nthFib(x)) + } + + def nthFib(n: Int): Int = { + if (n == 1) + return 1 + else if (n == 2) + return 1 + else + return nthFib(n-2) + nthFib(n-1) + } +} \ No newline at end of file