Find unit digit of x raised to power y | Java code to find the unit digit of x raised to power y . ; find unit digit ; Get last digit of x ; Last cyclic modular value ; here we simply return the unit digit or the power of a number ; Driver code ; get unit digit number here we pass the unit digit of x and the last cyclicity number that is y % 4
import java . io . * ; import java . util . * ; class GFG { static int unitnumber ( int x , int y ) { x = x % 10 ; if ( y != 0 ) y = y % 4 + 4 ; return ( ( ( int ) ( Math . pow ( x , y ) ) ) % 10 ) ; } public static void main ( String [ ] args ) { int x = 133 , y = 5 ; System . out . println ( unitnumber ( x , y ) ) ; } }