Issue
I am new to kotlin
From what I understanding this code should be working but it isn't
fun main(args: Array<Int>) {
//printing out the first element of the array
println(args[0])
}
main([12,3,4,5])
Solution
The main
function is the program entry point and needs to have a specific function signature.
Also, to create an array in Kotlin from hard-coded elements you would use arrayOf()
. You can find more about it here.
A working example would be:
fun main()
{
test(arrayOf(12,3,4,5))
}
fun test(args: Array<Int>) {
//printing out the first element of the array
println(args[0])
}
Answered By - Halex
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.