You seem to be making this a lot more complicated than it needs to be.
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int p = a;
int r;
while (p > 0) {
r = p % 10;
System.out.print(r);
p /= 10;
}
If the input is 214, then the above code will print 412.
CLICK HERE to find out more related problems solutions.