Write a Kotlin program that takes an integer input from the user and then calculates the cube of that number. This calculation should be stored in a val variable and the program should print the cube of given number. Assume that the number is always a positive integer.
Constants and val variables
Calculating the cube of a user-specified integer
Report a typo
Sample Input 1:
4Sample Output 1:
64Sample Input 2:
2Sample Output 2:
8Write a program in Kotlin
import java.util.*
fun main(args: Array<String>) {
val scanner = Scanner(System.`in`)
// Get user input
val userInput = scanner.nextInt()
// Calculate the cube of userInput
// Print the result
}
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.