Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File
- import java.io.FileWriter
- import java.io.InvalidObjectException
- import javax.management.ImmutableDescriptor
- import kotlin.random.Random
- //funzioni lambda
- //fun greaterThanLength(s1: String, s2: String): Boolean = s1.length>s2.length
- //fun contaVocali(s: String) : Int {
- // var cont = 0
- // for (c in s) if (c in "aAeEiIoIuU") cont++
- //
- // return cont
- //}
- //
- //fun haPiuVocali(s1: String, s2: String): Boolean = contaVocali(s1) > contaVocali(s2)
- fun String.contaVocali() : Int {
- var cont = 0
- for (c in this) if (c in "aAeEiIoIuU") cont++
- return cont
- }
- fun String.countVowels(): Int {
- val vowels = "aeiouAEIOU"
- var count = 0
- for (char in this) {
- if (char in vowels) {
- count++
- }
- }
- return count
- }
- fun posMassimo(elenco: MutableList<String>, comparatore: (s1: String, s2: String) -> Boolean ): Int
- {
- if (elenco.count() == 0) return -1
- var pos = 0
- if (elenco.size>=2)
- for (i in 1..elenco.lastIndex)
- if (comparatore(elenco[i], elenco[pos])) //(greaterThan(elenco[i], elenco[pos])) //(elenco[i]>elenco[pos])
- pos = i
- return pos
- }
- fun main() {
- val registroAula =
- arrayListOf<String>("Azzino", "Castrovillari", "Aiuliao", "Amati", "Zucchetti", "Pinturin", "Singh")
- println("Massimo: ${registroAula[posMassimo(registroAula) { s1: String, s2: String ->
- s1.contaVocali() > s2.contaVocali()}] }")
- //println("Massimo: ${registroAula[posMassimo(registroAula, ::haPiuVocali)]}")
- }
Advertisement
Add Comment
Please, Sign In to add comment