I am having a hard time figuring out the solution to this problem. I am trying to develop a program in Java that takes a number as an input and prints the sum of power of each digit such that the power of nth digit is (n-1)th digit. However for the first digit, the power should be that of last digit. for example we have a input of 123 then the pattern should be 1^3 + 2^1 + 3^2. This has been confusing me and I would appreciate anyone's ideas.

```
import java.util.Scanner;

public class MyTest {
    public static void main(String[] args) {

        int input;
        Scanner scanner = new Scanner(System.in);
        input = scanner.nextInt();
        System.out.println(logic(input));
    }

    public static int logic(int input) {
        int sum = 0;
        while (input != 0) {
            sum = sum + input % 10;
            input = input / 10;
        }
        return sum
    }
}

```

This is all i got till now. 

Formula is:

if input number is 123 then final result should be sum of:

```
1 ^ 3 + 2 ^ 1 + 3 ^ 2

```