Q:

Kotlin program of print the first, last, and step value of a range

belongs to collection: Kotlin Ranges Programs

0

In this program, we will create an integer range using the (..) operator, and will print the first element of the list using ".first", last element of the list using ".last", and the value of the step using ".step".

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

fun main(args: Array<String>) {	
	// print first element of the range
	println((1..10 step 2).first)

	// print first element of the range
	println((1..10 step 2).last)

	// print value of the step
	println((1..10 step 2).step)
}

Output:

1
9
2

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Kotlin example of reversed() function with integer... >>
<< Kotlin program of character range using downTo() f...