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.
123456789fun main() { 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") }
すべて明確でしたか?
フィードバックありがとうございます!
セクション 1. 章 4
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください
セクション 1. 章 4