Unresolved reference: num1 in Kotlin, How to fix this error?


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: KotlinUnresolved reference: num1 in Kotlin, How to fix this error?
chetan shidling asked 5 years ago

Here is the code:
 
fun main(args : Array<String>){
add(41,22)
}
fun add(num1 : Int, num2 : Int){
println(“The sum is :” num1 + num2)
}

1 Answers
Krishna answered 5 years ago

Put $ symbol and run the code. Ok, I will try and share.
 
Code:
 
fun main(args : Array<String>){
add(41,22)
}
fun add(num1 : Int, num2 : Int){
println(“The sum is : ${num1 + num2}”)
}
 
Output:
 
The sum is : 63