Example: #1 - Check the number is a Palindrome
Check the number is a Palindrome using a divide and modulus approach
Kotlin Input Screen
fun main(args: Array<String>) {
val originalNumber = 12321
var reverseNumber = 0
var temp = originalNumber
while (temp > 0) {
val remainder = temp % 10
reverseNumber = (reverseNumber * 10) + remainder
temp = temp / 10
}
if (originalNumber == reverseNumber) {
println("The given number is Palindrome")
} else {
println("The given number is NOT a Palindrome")
}
}
Kotlin Output Screen
The given number is Palindrome