Q:

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

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now