Collections
Counting Groups
Count values on each side of a threshold.
Counting Groups
CountingGroups.scala
object Main {
def main(args: Array[String]): Unit = {
val threshold =
val values = List(1, 2, 3, 4, 5)
var small = 0
var large = 0
for (value <- values) {
if (value <= threshold) {
small = small + 1
} else {
large = large + 1
}
}
println("threshold=" + threshold)
println("small=" + small)
println("large=" + large)
}
}
object Main {
def main(args: Array[String]): Unit = {
val threshold =
val values = List(1, 2, 3, 4, 5)
var small = 0
var large = 0
for (value <- values) {
if (value <= threshold) {
small = small + 1
} else {
large = large + 1
}
}
println("threshold=" + threshold)
println("small=" + small)
println("large=" + large)
}
}
object Main {
def main(args: Array[String]): Unit = {
val threshold =
val values = List(1, 2, 3, 4, 5)
var small = 0
var large = 0
for (value <- values) {
if (value <= threshold) {
small = small + 1
} else {
large = large + 1
}
}
println("threshold=" + threshold)
println("small=" + small)
println("large=" + large)
}
}
counting-groups
Grouping can start with simple counters. Each loop pass updates the count for one group.