CS Electrical And Electronics
@cselectricalandelectronics

Code to print both index numbers and values in Kotlin?

All QuestionsCategory: KotlinCode to print both index numbers and values in Kotlin?
chetan shidling asked 3 years ago

I need short information.

1 Answers
chetan shidling answered 3 years ago

Here is the code to print both index numbers and values in Kotlin.
 
fun main(args : Array<String>){
var nums = listOf(1,2,3,4)

for((i,e) in nums.withIndex())
{
println(” $i : $e”)
}
}
 
Output:
 
0 : 1
1 : 2
2 : 3
3 : 4