How to get the last digit of a big int in Kotlin

1 Answer

0 votes
import java.math.BigInteger

fun main() {
    val bigInt = BigInteger("12345678901234567890123456789012")

    // Get the last digit using modulo 10
    val lastDigit = bigInt % BigInteger.TEN

    println("The last digit is: $lastDigit")
}



  
/*
run:

The last digit is: 2

*/

 



answered Aug 27, 2025 by avibootz

Related questions

1 answer 105 views
1 answer 86 views
1 answer 72 views
1 answer 72 views
1 answer 90 views
1 answer 83 views
1 answer 71 views
...