Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operator overloading in Kotlin [closed]

String division using operator overloading in Kotlin, please help me to complete this code. No change can be made in main function. Find common from both string like a=aabcc b=abdec answer=abc (unique common characters)

fun main(args: Array<String>) 
{
      val a:String = readLine()!!

      val b:String = readLine()!!

      val result = a/b

      println(result)
 }
like image 218
divyesh Avatar asked Feb 27 '26 19:02

divyesh


1 Answers

Operators can be defined externaly, just like extension functions:

operator fun String.div(other: String): String {
    // Put your implementation here
}

As for the implementation: you should probably do your assignment yourself.

like image 168
madhead - StandWithUkraine Avatar answered Mar 02 '26 15:03

madhead - StandWithUkraine