Find last digit in factorial | Java program to find last digit in factorial n . ; Explicitly handle all numbers less than or equal to 4 ; For all numbers greater than 4 the last digit is 0 ; Driver code
import java . io . * ; import java . util . * ; class GFG { static int lastDigitFactorial ( int n ) { if ( n == 0 ) return 1 ; else if ( n <= 2 ) return n ; else if ( n == 3 ) return 6 ; else if ( n == 4 ) return 4 ; else return 0 ; } public static void main ( String [ ] args ) { System . out . println ( lastDigitFactorial ( 6 ) ) ; } }