Code to print both index numbers and values in Kotlin?


Warning: Trying to access array offset on false in /home3/indiakep/public_html/wp-content/plugins/dw-question-answer/inc/Template.php on line 8
All QuestionsCategory: KotlinCode to print both index numbers and values in Kotlin?
chetan shidling asked 5 years ago

I need short information.

1 Answers
chetan shidling answered 5 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