CodeBlanks Logo Icon CodeBlanks

Summary - Data types

Combine Int, Double, String and Boolean to write a calculation card.

Summary - Data types

So far you've learned integer types, floating-point types, Boolean, Char, String, Any and Unit. Each type has a purpose: Int and Long for integers, Double for floating-point, Boolean for conditions, Char for one character, String for text.

Any is the supertype of all; Unit marks functions that return no value.

Practice Put it together

At the top level, declare val name: String = "Kotlin". Inside fun main(), print the length with println(name.length).

Sample solution

Main.kt
val name: String = "Kotlin"

fun main() {
    println(name.length)
}

Expected output

6

Next step

Congratulations! You've completed the data types group. In the next group you'll build a calculator project: step by step you'll add functions and complete a working app from start to finish. You'll experience addition, subtraction, multiplication, division and error handling in a real project.

This project will bring together all the fundamentals you've learned.

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which is the default type for floating-point?

  • Float
  • Double Correct answer
  • Int
  • Long

Explanation: Double is the default floating-point type.

2 Match the concepts

Term Meaning
Int Integer
Double Floating-point
Boolean true/false
String Text

3 Summary - Data types: fill in the missing part

Question
val active: ____ = true
Answer
val active: Boolean = true

Explanation: A true/false value is of type Boolean.

All lessons in Beginner