I wrote this code to find last digit of a exponent b but SPOJ says its wrong. I tried almost all test cases but couldn't find the error. Problem:http://www.spoj.com/problems/LASTDIG/ My Solution:
package spoj;
import java.util.Scanner;
public class LastDigit {
public static void main(String[] args) throws java.lang.Exception {
Scanner p = new Scanner(System.in);
for(int test = p.nextInt();test>0;test-- ){
int a = p.nextInt();
int b = p.nextInt();
int result = (int) Math.pow(a,b);
System.out.println(result%10);
}
}
}