Start learning free

LESSON 174 OF 414 · PROJECTS: EVERYDAY PROGRAMS

Report Card V1 - One Subject Average in Scala

Practice

Compute a student's average score across three tests using integer division so the result is a whole number.

You start with:

val test1: Int = 85
val test2: Int = 92
val test3: Int = 78

Build:

Average: 85

Rules:

  • Compute the integer average of test1, test2, and test3 using integer division (Int divided by Int already drops the remainder).
  • Print "Average: " followed by the average, for example println(s"Average: $average")

Scala's Int / Int truncates, so (test1 + test2 + test3) / 3 already gives an integer.

val test1: Int = 85
val test2: Int = 92
val test3: Int = 78

val average: Int = (test1 + test2 + test3) / 3
println(s"Average: $average")

STEP 1 OF 2
    Ctrl + Enter to check

    Report Card V1 in Scala

    Keep going with ScalaAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free