Зміст курсу
Android Development with Kotlin
Android Development with Kotlin
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
fun 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 (
var
orval
). - Assign data types to these variables.
- Subtract the
discount
amount 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")
}
Дякуємо за ваш відгук!