BAEL-2648

This commit is contained in:
Rodrigo Graciano 2019-02-15 23:43:15 -05:00
parent 91ac058838
commit ad3fe3d536
8 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package com.baeldung.range
fun main(args: Array<String>) {
for (ch in 'a'..'f') {
print(ch)
}
println()
for (ch in 'f' downTo 'a') {
print(ch)
}
}

View File

@ -0,0 +1,18 @@
package com.baeldung.range
fun main(args: Array<String>) {
val r = 1..10
//Apply filter
val f = r.filter { it -> it % 2 == 0 }
println(f)
//Map
val m = r.map { it -> it * it }
println(m)
//Reduce
val rdc = r.reduce { a, b -> a + b }
println(rdc)
}

View File

@ -0,0 +1,8 @@
package com.baeldung.range
fun main(args: Array<String>) {
println((1..9).first)
println((1..9 step 2).step)
println((3..9).reversed().last)
}

View File

@ -0,0 +1,14 @@
package com.baeldung.range
fun main(args: Array<String>) {
val r = 1..20
println(r.min())
println(r.max())
println(r.sum())
println(r.average())
println(r.count())
val repeated = listOf(1, 1, 2, 4, 4, 6, 10)
println(repeated.distinct())
}

View File

@ -0,0 +1,28 @@
package com.baeldung.range
fun main(args: Array<String>) {
for (i in 1..9) {
print(i)
}
println()
for (i in 9 downTo 1) {
print(i)
}
println()
for (i in 1.rangeTo(9)) {
print(i)
}
println()
for (i in 9.downTo(1)) {
print(i)
}
println()
for (i in 1 until 9) {
print(i)
}
}

View File

@ -0,0 +1,14 @@
package com.baeldung.range
fun main(args: Array<String>) {
(1..9).reversed().forEach {
print(it)
}
println()
(1..9).reversed().step(3).forEach {
print(it)
}
}

View File

@ -0,0 +1,15 @@
package com.baeldung.range
fun main(args: Array<String>) {
for(i in 1..9 step 2){
print(i)
}
println()
for (i in 9 downTo 1 step 2){
print(i)
}
}

View File

@ -0,0 +1,8 @@
package com.baeldung.range
fun main(args: Array<String>) {
for (i in 1 until 9) {
print(i)
}
}