Amaliy ish №3
O’zbekcha so’zlardan iborat satr berilgan. Satrdagi eng uzun va eng kichik
so’z uzunligini aniqlovchi dastur yozing.
fun main() {
var listOfStrings = readLine()!!.split(' ')
var max = listOfStrings.maxBy { it.length }!!.length
var min = listOfStrings.minBy { it.length }!!.length
println("max string is ${max}")
println("min string is ${min}")
}
O’zbekcha so’zlardan iborat satr berilgan. So’zlar orasida probellar bir
nechta va shu satrdagi ortiqcha probellarni olib tashlovchi sodda dastur
yozing.
fun main() {
var listOfStrings = readLine()?.split(' ')
var ansString = ""
listOfStrings?.forEach {
ansString+= if (it!="")"${it} " else ""
}
ansString = ansString.trim()
println(ansString)
}
Do'stlaringiz bilan baham: |