You are given a number 'n'. Write a Kotlin program to print the square of this number 'n'. Your function should scan a number 'n' as input and as output it should print the square of 'n'.
Standard output
Print the square of a given number
Report a typo
Sample Input 1:
4Sample Output 1:
16Sample Input 2:
10Sample Output 2:
100Write a program in Kotlin
// Necessary imports
import java.util.Scanner
fun main(args: Array<String>) {
// Your code here: Create a Scanner object to read the input
val scanner = Scanner(System.`in`)
// Your code here: Read an integer using the Scanner object
val n = scanner.nextInt()
// Your code here: Calculate and print the square of n
}
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.