groovy-lecture/live/solutions/bedingungen.groovy

20 lines
362 B
Groovy
Raw Normal View History

2024-06-07 22:06:00 +02:00
def myList = [1,2,3,4,5,6,7,8,9,10]
def emptyList = []
def check(List<Integer> list) {
def counter = 0
if (list.size() == 0) {
return "Die übergebene Liste ist leer!"
}
for(i in 0..<list.size()) {
if(list[i] % 2 == 0) {
counter++
}
}
return counter
}
println check(myList)
println check(emptyList)