The aim of the application is to display a number sequence and the user has to choose the sixth digit:
1 2 3 5 8 ...
Although this Q&A has been checked, another code had to be created in order to meet the demands of the application, namely returning the sixth digit of the number sequence.
Test
import org.scalatest.FunSuite
import org.scalatest.FunSpec
import org.scalatest.matchers.ShouldMatchers
class CalculationTest extends FunSuite {
test("fibonacci") {
assert(calculation.fibonacci(1, 2) === 13)
}
}
Main
object Calculation {
def fibonacci(a: Int, b: Int) : Int = {
var first:Int = a
var second:Int = b
var third:Int = 0
var fourth:Int = 0
var fifth:Int = 0
var sixth:Int = 0
third = first + second
fourth = second + third
fifth = third + fourth
sixth = fourth + fifth
return sixth
}
}
Is it possible to simplify the main code, e.g. just returning the sixth digit instead of calculating each individual digit?