groovy-lecture/live/solutions/bedingungen.groovy

20 lines
373 B
Groovy
Raw Permalink 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(int i = 0; i < list.size(); i++) {
2024-06-07 22:06:00 +02:00
if(list[i] % 2 == 0) {
counter++
}
}
return counter
}
println check(myList)
println check(emptyList)