Challenge: Variables and Data Types
Let's move on to practice!
You already know what variables and data types exist in Kotlin, so it's time to test your knowledge with a simple task.
In this task, you need to determine the way of declaration for each variable (var or val). Then, you should assign data types to these variables. Afterward, subtract the discount amount from the item price, store this value in a variable named price, and finally, print the value of this variable to the console.
It's not as difficult as it sounds, and you can always use hints or peek at the solution for guidance!
Main.kt
123456789fun main() { val productName: ___ = "Bread" var price: ___ = 13.80F val discount: ___ = 4 // calculate the price after discount and print it to the console price = ___ print("Price after the discount is ___") }
- Determine the declaration type for each variable (
varorval). - Assign data types to these variables.
- Subtract the
discountamount from the product price and save this value in the variableprice. - Print the value of the price variable to the console.
val productName: String = "Bread"
var price: Float = 13.80F
val discount: Int = 4
// calculate the price after discount and print it to the console
price = price - discount
print("Price after the discount is $price")
}
Tack för dina kommentarer!
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 5.26
Challenge: Variables and Data Types
Svep för att visa menyn
Let's move on to practice!
You already know what variables and data types exist in Kotlin, so it's time to test your knowledge with a simple task.
In this task, you need to determine the way of declaration for each variable (var or val). Then, you should assign data types to these variables. Afterward, subtract the discount amount from the item price, store this value in a variable named price, and finally, print the value of this variable to the console.
It's not as difficult as it sounds, and you can always use hints or peek at the solution for guidance!
Main.kt
123456789fun main() { val productName: ___ = "Bread" var price: ___ = 13.80F val discount: ___ = 4 // calculate the price after discount and print it to the console price = ___ print("Price after the discount is ___") }
- Determine the declaration type for each variable (
varorval). - Assign data types to these variables.
- Subtract the
discountamount from the product price and save this value in the variableprice. - Print the value of the price variable to the console.
val productName: String = "Bread"
var price: Float = 13.80F
val discount: Int = 4
// calculate the price after discount and print it to the console
price = price - discount
print("Price after the discount is $price")
}
Tack för dina kommentarer!