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

1 Answer

0 votes
import scala.math.BigInt

object LastDigitExample {
  def main(args: Array[String]): Unit = {
    // Example BigInt
    val bigNumber: BigInt = BigInt("12345678901234567890123456789123")

    // Get the last digit
    val lastDigit: Int = (bigNumber % 10).toInt

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


 
/*
run:
  
The last digit of 12345678901234567890123456789123 is: 3
  
*/

 



answered Aug 27, 2025 by avibootz

Related questions

1 answer 82 views
1 answer 72 views
1 answer 72 views
1 answer 90 views
1 answer 83 views
1 answer 71 views
2 answers 84 views
...