Home > Mobile >  Too many arguments for public inline fun println(): Unit defined in kotlin.io
Too many arguments for public inline fun println(): Unit defined in kotlin.io

Time:06-06

I am trying to make a simple program that let you add just two numbers (just learning basics) and i just "fell" to this problem:

GODCalculator.kt: (18, 15):Too many arguments for public inline fun println(): Unit defined in kotlin.io

I tried to find some anwsers on internet, but didn't find excatly what i wanted to... nothing solved my issue

fun addition(){
println("So please insert two numbers, the program i mean the god will solve your math problem.")
print("Number #1: "); val z = readLine()!!.toInt()
print("\n")
print("Number #2: "); val c = readLine()!!.toInt()
val v = c z
println(z,"   " ,c, " = ",v)

Problem with: println(z," " ,c, " = ",v)

but i also tried with " " edition like this: println(z " " c " = " v)

both didn't work :/

I use: IntelliJ IDEA Community Edition, but I don't think it matters anyway I am learning Kotlin on console, because when i tried to start use Android Studio i just got scared how many i have to know...

Edit: Thanks to lpizzinidev. His anwser totally fixed my issue... The correct way is: println("$z $c = $v")

CodePudding user response:

You can use string interpolation:

println("$z   $c = $v")

If you want to use string concatenation you should first convert the integers to a string with .toString():

println(z.toString()   "   "   c.toString()   " = "   v.toString())

The former approach is more verbose.

  • Related