0

Right now, I'm not working on any major projects. Just daily, bite-sized exercises and coding drills. This week = writing basic Kotlin functions. So out of my curiosity, why is Android Studio showing an "unexpected tokens" and "expecting ')' " errors for the params in my main function? The line that reads "(num1:5; num2:4)".

This is the exact format I'm seeing when I look up how to write it, but when I try to do, I keep getting errors. I even tried to copy and paste samples or snippets of code I found online, and the same thing always happens.

fun main()
{
    addition(num1:5; num2:4)
}

fun addition(num1: Int, num2: Int)
{
    println(num1 + num2)
}

2 Answers 2

1

The syntax is invalid.

Try with:

fun main() {
    addition(num1= 5, num2= 4) 
}

fun addition(num1: Int, num2: Int) {
    println(num1 + num2) 
}
Sign up to request clarification or add additional context in comments.

Comments

0

Hope this helps you to understand better! Kotlin Default Parameters

1 Comment

Thank you for the resource! Much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.