ADVERTISEMENT
ADVERTISEMENT

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

Learn how to print the first, last, and step value of a range in Kotlin?
Submitted by IncludeHelp, on March 26, 2022

In the below 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".

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

Kotlin Ranges Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.