Hi, I've been having problems with this one for some time now solving this problem in Java. Shows WA. I also read different approaches on the forum to this issue but haven't found solution for my problem. Can you take a look at my code?
import java.util.Scanner;
public class Main{
public static void main (String[] args){
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
for (int i=0; i<t; i++){
String[] digits = sc.nextLine().split("\\s");
int a = Integer.parseInt(digits[0].substring(digits[0].length()-1));
int x = (digits[1].length()<2)? 1 : 2;
int b = Integer.parseInt(digits[1].substring(digits[1].length()-x));
if (a == 1 || b == 0)
System.out.println(1);
else if (a == 0)
System.out.println(0);
else{
if (b % 4 == 0)
b = 4;
else
b = b % 4;
System.out.println((int)Math.pow(a, b)%10);
}
}
sc.close();
}
}