ADVERTISEMENT
ADVERTISEMENT

Kotlin program of character range using (..) operator

Learn how to create character range using (..) operator in Kotlin?
Submitted by IncludeHelp, on March 26, 2022

(..) Operator

The (..) operator is the simplest way to create a range. It creates a range from the given start and end values. It is the operator form of rangeTo() function.

Here, we will demonstrate the example of creating a character range using the (..) operator.

Example 1:

fun main(args : Array<String>){
	// creating character ranges
	println("Character range 1:")	
	for(x in 'a'..'g'){
		println(x)
	}
	println()

	println("Character range 2:")	
	for(x in 'g'..'p'){
		println(x)
	}
	println()
}

Output:

Character range 1:
a
b
c
d
e
f
g

Character range 2:
g
h
i
j
k
l
m
n
o
p

Example 2:

fun main(args : Array<String>){
	// creating character ranges
	println("Character range 1:")	
	for(x in 'a'..'g' step 3){
		println(x)
	}
	println()

	println("Character range 2:")	
	for(x in 'g'..'p' step 3){
		println(x)
	}
	println()
}

Output:

Character range 1:
a
d
g

Character range 2:
g
j
m
p

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.