Lesson contents

24 core lessons

Scala programming tutorials

Learn Scala with setup instructions, runnable lessons, and library references covering collections, text, dates, and numerical operations.

Scala core curriculum

Getting started

  1. Environment setup
  2. Hello World
  3. Programming fundamentals
  4. Values and integer arithmetic
  5. Data types and type inference
  6. Stable values with val and final val
  7. Comparisons and short-circuit operators

Decisions and loops

  1. If, else if, and else
  2. Choosing a value with an if expression
  3. Pattern matching with match and case
  4. For loops and indexed traversal
  5. While loops and mutable state
  6. Post-test loops in Scala 2 and Scala 3
  7. Early exit with takeWhile
  8. Skipping iterations with for guards

Functions and data

  1. Functions and expression results
  2. Counting values with groupMapReduce
  3. Parsing strings with pattern matching
  4. Modeling values with case classes
  5. Validating input with Option

Files and projects

  1. Managing files with Using.resource
  2. Sealed traits and pattern matching
  3. Organizing code across files
  4. Inventory project with boundary tests

Check a three-digit Armstrong number

Scala source
object ArmstrongNumber {
  
    def main(args: Array[String]) = {

        val input = 153;

        var sum = 0;
        var armstrongNumber = input;

        while (armstrongNumber > 0) {
            var i = armstrongNumber % 10;
            armstrongNumber = armstrongNumber / 10;
            sum += (i * i * i);
        }

        if (sum == input) {
            println("The given number is an Armstrong number");
        } else {
            println("The given number is not an Armstrong number");
        }
    }
}
Output
The given number is an Armstrong number