0% found this document useful (0 votes)
2 views1 page

Day 2

The document provides an overview of Kotlin basics, including variable types, type conversion, and data types such as integers, doubles, and strings. It explains mutable and immutable variables, user input handling, control flow with if-else and when statements, and loops. Additionally, it covers operators for arithmetic, comparison, assignment, and logical operations.

Uploaded by

manmeeth.bajwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Day 2

The document provides an overview of Kotlin basics, including variable types, type conversion, and data types such as integers, doubles, and strings. It explains mutable and immutable variables, user input handling, control flow with if-else and when statements, and loops. Additionally, it covers operators for arithmetic, comparison, assignment, and logical operations.

Uploaded by

manmeeth.bajwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

KOTLIN BASICS Variables Type Conversion Datatypes

Definition: Containers for storing data Integers:


values.
Examples:
val age: Int = 25
Numbers to Double:
Syntax: val double: Double = integer.toDouble()
val largeNumber: Long = 10000000000L

Mutable:
var variableName: DataType = value Numbers to String: Floats and Doubles:
val stringNumber: String = val pi: Double = 3.14
number.toString()
Immutable: val floatNumber: Float = 2.73F
val constantName: DataType = value
Strings to Int:
val intNumber: Int = stringNumber.toInt() Booleans:
Examples: val isTrue = true
val isFalse = false
var age: Int = 30
User Input Logical Operators: | | (OR), && (AND), ! (NOT)
val pi: Double = 3.14
var name = "John Doe"
val isAdult = true Syntax: Char:
val letter: Char = 'A'
Display message:
Unicode: val heart: Char = '\\u2764'
println("What is your name?")
val vs. var: Special Characters: \n (New line), \t (Tab)

val : Immutable, cannot be Read input: Strings:


reassigned. val userName = readLine()
val simpleString: String = "Hello, World!"

var : Mutable, can be reassigned. Output: Concatenation:


println("Hello, $userName!") val fullName = firstName + " " + lastName

Control Flow: if and


Control Flow: when
else if Statements Operators
Statements

Syntax: Syntax:
when (value) { 1 -> println("It is
Arithmetic:
if (condition) { // code }
else if (condition) { // code }
one.") 2 -> println("It is two.") else -> +,/,%
println("It is not one or two.") }
else { // code } Comparison:
== , != , > , < , >= , <=
Examples:
Assignment:
if (age >= 18) { println("You are = , += , = , = , /=
eligible to vote.") } else {
println("You are not Logical:
eligible to vote.") }
&& , | | , !

Loops: while Loops

Syntax:
while (condition) { // code }

Countdown:
kotlinCopy codevar countdown = 5
while (countdown > 0) { println("Countdown: $countdown")
countdown--
}
println("Blast off!")

You might also like