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 84 views
1 answer 75 views
1 answer 76 views
1 answer 92 views
1 answer 85 views
1 answer 72 views
2 answers 87 views
...