区间
区间的创建
1 .
val intRange = 1 .. 10 //[1,10]
val charRange = 'a' .. 'z' //[a,z]
val longRange = 1L .. 100L //[1,100]
val intRangeExclusive = 1 until 10 //[1,10)
val charRangeExclusive = 'a' until 'z' //[a,z)
val longRangeExclusive = 1L until 100L //[1,100)
//倒序空间;
val intRangeReverse = 10 downTo 1 //[10,1]
val charRangeReverse = 'z' downTo 'a' //[z,a]
val longRangeReverse = 100L downTo 1L //[100,1]
//区间的步长;
val intRangeWithStep = 1 .. 10 step 2 //结构是[1,3,5,7,9];
val charRangeWithStep = 'a' .. 'z' step 2 //;
val longRangeWithStep = 1L .. 100l step 5 //结构是[1,6,11,16 .....];
//区间的迭代;
val intRange = 1 .. 10 //[1,10]
for(element in intRange){
println(element)
}
intRange.forEach{
println(it)
}
//区间是否包含某个值;
val intRange = 1 .. 10 //[1,10]
if(3 in intRange){
println("3 in range 'intRange'")
}
//区间是否不包含某个值;
val intRange = 1 .. 10 //[1,10]
if(3 !in intRange){
println("3 not in range 'intRange'")
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
---------------last line for now----------------