For this Question: Given a string S consisting of digits between 1 and 9. Rearrange the string such that the number of even substrings it contains is maximised. A substring is said to be even if the number it represents is even.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>solve()</b> that takes the string S as parameter.

<b>Constraints</b>
1<=|S|<=1000

S only contains digits between 1 and 9 (both inclusive).Return the number of even substrings present in the string after rearranging it such that the number is maximised.Sample Input:
1232

Sample Output:
7

We will rearrange the string to "1322". Now, the seven even substrings are "132", "32", "2", "2", "1232", "232", "32". Two substrings are considered different if at least one of the starting or ending index differs from the other., I have written this Solution Code: 

class Solution {
    public long solve(String S) {
        int e = 0;
        for (int i = 0; i < S.length(); i++) {
            int y = S.charAt(i) - '0';
            if (y % 2 == 0) {
                e++;
            }
        }
        long ans = 0;
        for (int i = S.length(); i >= 0; i--) {
            if (e > 0) {
                ans += i;
                e--;
            }
        }
        return ans;
    }
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not?