Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Kotlin Data Types | Kotlin Variables and Data Types
Introduction to Kotlin

bookKotlin Data Types

Kotlin includes several built-in data types that you will use frequently as you write programs. Understanding these types helps you store and work with different kinds of information in your code. The most common data types in Kotlin are:

  • Int: use this type to store whole numbers, such as counts, ages, or any value without a fractional part;
  • Double: use this type for numbers with decimals, like measurements or calculations that require precision;
  • Boolean: use this type for values that can only be either true or false, such as flags or conditions;
  • String: use this type to store text, such as names, messages, or any sequence of characters.

Each data type serves a specific purpose, and choosing the right one makes your code clearer and safer. Next, you will see how to declare variables of these types and print their values.

Main.kt

Main.kt

copy
1234567891011121314151617
package com.example fun main() { // Integer value val age: Int = 25 // Double value val height: Double = 1.75 // Boolean value val isStudent: Boolean = true // String value val name: String = "Alex" println("Name: $name") println("Age: $age") println("Height: $height") println("Is student: $isStudent") }

In this code, you see four variables, each using a different Kotlin data type. The variable age is declared as an Int to hold a whole number. The variable height uses the Double type for a decimal value. The isStudent variable is a Boolean, representing a true/false condition. Finally, name is a String, storing a sequence of characters. Each variable is printed using string templates, which let you easily include variable values in text output. This example shows how each data type is used in practice and how you can display their values in your program.

question mark

Which of the following Kotlin variable declarations is correct for storing a decimal number?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

bookKotlin Data Types

Desliza para mostrar el menú

Kotlin includes several built-in data types that you will use frequently as you write programs. Understanding these types helps you store and work with different kinds of information in your code. The most common data types in Kotlin are:

  • Int: use this type to store whole numbers, such as counts, ages, or any value without a fractional part;
  • Double: use this type for numbers with decimals, like measurements or calculations that require precision;
  • Boolean: use this type for values that can only be either true or false, such as flags or conditions;
  • String: use this type to store text, such as names, messages, or any sequence of characters.

Each data type serves a specific purpose, and choosing the right one makes your code clearer and safer. Next, you will see how to declare variables of these types and print their values.

Main.kt

Main.kt

copy
1234567891011121314151617
package com.example fun main() { // Integer value val age: Int = 25 // Double value val height: Double = 1.75 // Boolean value val isStudent: Boolean = true // String value val name: String = "Alex" println("Name: $name") println("Age: $age") println("Height: $height") println("Is student: $isStudent") }

In this code, you see four variables, each using a different Kotlin data type. The variable age is declared as an Int to hold a whole number. The variable height uses the Double type for a decimal value. The isStudent variable is a Boolean, representing a true/false condition. Finally, name is a String, storing a sequence of characters. Each variable is printed using string templates, which let you easily include variable values in text output. This example shows how each data type is used in practice and how you can display their values in your program.

question mark

Which of the following Kotlin variable declarations is correct for storing a decimal number?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2
some-alt