Professional Documents
Culture Documents
Kotlin_Exercises
Kotlin_Exercises
Write a function `filterAndSum` that takes a list of integers and returns the sum of all even numbers in the list.
Example:
fun main() {
println(filterAndSum(numbers)) // Output: 12
Given a list of strings, write a function `longestString` that returns the longest string. If there are multiple strings with the
Example:
fun main() {
Create a class `Rectangle` with properties `width` and `height`. Add a method `area` that returns the area of the
rectangle and a method `perimeter` that returns the perimeter of the rectangle.
Example:
fun main() {
Write a function `applyOperation` that takes a list of integers and a function that operates on an integer, and returns a
new list where the function has been applied to each element.
Example:
fun main() {
Create a data class `Person` with properties `name` (String), `age` (Int), and `email` (String). Write a function
`createPeople` that returns a list of `Person` objects created from given input data.
Example:
fun main() {
println(people)
data class Person(val name: String, val age: Int, val email: String)
}
Exercise 6: Map and Filter
Write a function `findAdults` that takes a list of `Person` objects and returns a list of names of people who are 18 or
older.
Example:
fun main() {
data class Person(val name: String, val age: Int, val email: String)