Last digit of Product of two Large or Small numbers ( a * b ) | Java implementation of the above approach ; Function to print last digit of product a * b ; Driver code
class Solution { public static void lastDigit ( String a , String b ) { int lastDig = ( a . charAt ( a . length ( ) - 1 ) - '0' ) * ( b . charAt ( b . length ( ) - 1 ) - '0' ) ; System . out . println ( lastDig % 10 ) ; } public static void main ( String [ ] args ) { String a = "1234567891233" , b = "1234567891233156" ; lastDigit ( a , b ) ; } }