Write a program in Kotlin that displays the sum of squares of even numbers from 1 up to a given limit. Take the limit as an integer input from the user. If the limit is less than 0, print 'Invalid Input'.
Loops: repeat statement
Sum of squares of even numbers up to a limit
Report a typo
Sample Input 1:
10Sample Output 1:
220Sample Input 2:
5Sample Output 2:
20Write a program in Kotlin
import java.util.Scanner
fun main(args: Array<String>) {
// Create a Scanner object for taking input
val reader = Scanner(System.`in`)
// Read an integer input
val limit = reader.nextInt()
// Check if limit is less than 0
if (limit < 0) {
println("Invalid Input")
} else {
// Write a loop here to calculate the sum of squares of even numbers up to the limit
// Use the 'repeat' construct
// After calculating the sum, print it
}
}
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.