How to print text diagonally from left to right recursively in Kotlin

1 Answer

0 votes
fun printTextDiagonallyRecursivelyLTR(spaces: String, text: String) {
    if (text.isNotEmpty()) {
        println(spaces + text[0])
        printTextDiagonallyRecursivelyLTR(spaces + " ", text.substring(1))
    }
}

fun main() {
    printTextDiagonallyRecursivelyLTR("", "HELLO WORLD")
}


/*
run:

H
 E
  L
   L
    O
      
      W
       O
        R
         L
          D

*/

 



answered Apr 8 by avibootz

Related questions

...