Combine small integer, decimal, and boolean values.

primitive-types Basic types such as integers, doubles, and booleans carry different kinds of values through an expression.

Primitive Types

whole
PrimitiveTypes.scala
Replay: real traced execution (multi-file project)
object Main {
  def main(args: Array[String]): Unit = {
    val whole = 6
    val fraction = 2.5
    val aboveFive = whole > 5
    val total = whole + fraction

    println("whole=" + whole)
    println("aboveFive=" + aboveFive)
    println("total=" + total)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val whole = 3
    val fraction = 2.5
    val aboveFive = whole > 5
    val total = whole + fraction

    println("whole=" + whole)
    println("aboveFive=" + aboveFive)
    println("total=" + total)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val whole = 9
    val fraction = 2.5
    val aboveFive = whole > 5
    val total = whole + fraction

    println("whole=" + whole)
    println("aboveFive=" + aboveFive)
    println("total=" + total)
  }
}
  1. whole ← 6, fraction ← 2.5, aboveFive ← true, total ← 8.5

    1object Main {2  def main(args: Array[String]): Unit = {3    val whole→ 6 = 6 //@whole=3, 94    val fraction→ 2.5 = 2.55    val aboveFive→ true = whole6 > 56    val total→ 8.5 = whole6 + fraction2.578    println("whole=" + whole6)9    println("aboveFive=" + aboveFivetrue)10    println("total=" + total8.5)11  }12}
    outputwhole=6
    aboveFive=true
    total=8.5
  1. whole ← 3, fraction ← 2.5, aboveFive ← false, total ← 5.5

    1object Main {2  def main(args: Array[String]): Unit = {3    val whole→ 3 = 34    val fraction→ 2.5 = 2.55    val aboveFive→ false = whole3 > 56    val total→ 5.5 = whole3 + fraction2.578    println("whole=" + whole3)9    println("aboveFive=" + aboveFivefalse)10    println("total=" + total5.5)11  }12}
    outputwhole=3
    aboveFive=false
    total=5.5
  1. whole ← 9, fraction ← 2.5, aboveFive ← true, total ← 11.5

    1object Main {2  def main(args: Array[String]): Unit = {3    val whole→ 9 = 94    val fraction→ 2.5 = 2.55    val aboveFive→ true = whole9 > 56    val total→ 11.5 = whole9 + fraction2.578    println("whole=" + whole9)9    println("aboveFive=" + aboveFivetrue)10    println("total=" + total11.5)11  }12}
    outputwhole=9
    aboveFive=true
    total=11.5

Follow the Values

  1. whole starts at 6.
  2. fraction is 2.5.
  3. aboveFive = whole > 5 becomes true.
  4. total = whole + fraction becomes 8.5.
  5. The program prints whole=6, aboveFive=true, and total=8.5. | whole | fraction | aboveFive | total | | --- | --- | --- | --- | | 3 | 2.5 | false | 5.5 | | 6 | 2.5 | true | 8.5 | | 9 | 2.5 | true | 11.5 |

Exercise: PrimitiveTypes.scala

Reproduce total=8.5, then use whole 3 and 9 to predict aboveFive and total.