logo CodeStepByStep logo


Language/Type: Kotlin basics user input

Write Kotlin code that prompts the user for nonzero integers, and then prints the average of all even numbers typed. (When the user types 0, stop asking for input.) You may assume that the user types at least one even integer. The following is an example output from one run of your code:

Integer? 1
Integer? 3
Integer? 2
Integer? 6
Integer? 4
Integer? 10
Integer? 9
Integer? 0
Average: 5.5
Type your Kotlin solution code here:

This exercise asks for bare code. Submit a fragment of Kotlin code as described. Do not write any class or function/method heading around your code; just write the lines of code that will produce the result described.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.