Home > front end >  A Kotlin function that takes two parameters, a String and an Int
A Kotlin function that takes two parameters, a String and an Int

Time:12-06

I have a question. I would appreciate it if anybody can solve it. I already googled it and also did some efforts.

The question is: Create a function that takes two parameters, a String and an Int, and returns a String that contains the String parameter multiplied by the Int parameter. The function should not contain any loops and should be written in pure Kotlin.

It is important for me to use Kotlin methods.

For example the fuction must take "Mustafa" as the string and 5 as the int: The ouput must be: Mustafa Mustafa Mustafa Mustafa Mustafa

CodePudding user response:

I solved it by myself.

fun myFunction(s1: String, n1: Int): String {
    return s1.repeat(n1)
}

CodePudding user response:

fun stringIntMultiply (stringValue: String, intValue: Int): String = (stringValue.toInt() * intValue).toString()
  • Related