Palindroma en Kotlin

import java.io.File import java.io.IOException import java.io.FileReader import java.io.BufferedReader import java.io.InputStream import java.math.BigDecimal; object Main { @JvmStatic fun main(args:Array<String>){ demoMock() } fun demoMock(): Unit{ var cadena:String = "BOB"; println("${cadena}"); cadena = quitaEspacios(cadena); if(esPalindroma(cadena)){ println("Es palindroma"); }else{ println("No es palindroma"); } } fun esPalindroma(cadena:String):Boolean{ var resultado:Boolean=false; var cadenaTmp:String=""; var contador:Int = cadena.length; while(contador-->=0){ try{ var cr = cadena.get(contador); cadenaTmp += cr.toString(); }catch(ex: StringIndexOutOfBoundsException){ println(""); } } if(cadenaTmp.equals(cadena)){ resultado = true; } return resultado; } fun quitaEspacios(cadena:String):String{ var cadenaTmp:String=""; var contador:Int=cadena.length; while(contador-->= 0){ try{ var cx = cadena.get(contador); if(!" ".equals(cx.toString())){ cadenaTmp += cx.toString(); } //println("${cadenaTmp}") }catch(ex:StringIndexOutOfBoundsException){ println(""); } } return cadenaTmp; } }
Palindroma en Kotlin

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.