神奇的数字 偶数翻转 在eclipse运行不了,如何解决?(语言-java)

  1. 神奇的数字 将字符串数字中为偶数位的数字进行翻转,将翻转后的结果进行输出。 输入:"1234" 输出:"1432"
    public class Solution{
    public String change (String number) {
    if(number.equals("")) {
    return number;
    
    }//如果是空字符串原样返回
    char[] cs = number.toCharArray();
    int first=0;
    //定义头指针
    int last=cs.length-1;
    //定义尾指针
    while(first<last) {
    //循环执行条件,即头指针的位置在尾指针前面,如果在后面说明已经交换完毕
    if((cs[first]%2==0) && (cs[last]%2==0)) {
    //如果两数都是偶数执行交换操作(Ascll码编号与对应数字的奇偶一致)
    char temp = cs[first];
    cs[first]=cs[last];
    cs[last]=temp;
    first++;
    //头指针后移
    last--;
    //尾指针前移
    }else if((cs[first]%2==0) && (cs[last]%2!=0)) {
    //头指针所在为偶数
    last--;
    //头指针等待,尾指针前移
    }else if((cs[first]%2!=0) && (cs[last]%2==0)) {
    //尾指针所在为偶数
    first++;
    //尾指针等待,头指针后移
    }else {
    //头尾指针都不是偶数
    last--;
    //尾指针前移
    first++;
    //头指针后移
    }
    
    }
    String str = new String(cs);
    return str;
    }
    }

直接可运行的代码如下

public class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String number = scanner.next();
        Solution solution = new Solution();
        System.out.println(solution.change(number));
    }

    public String change(String number) {
        // write code here
        char[] a = number.toCharArray();
        Stack<Character> b = new Stack<>();
        int left = 0;
        int right = a.length - 1;
        while (right >= left)//遍历字符串
        {
            if (a[left] % 2 == 0) {
                b.push(a[left]);//把偶数字符入栈
            }
            left++;
        }
        left = 0;
        while (right >= left) {
            if (a[left] % 2 == 0) {
                a[left] = b.peek();//替换偶数字符
                b.pop();
            }
            left++;
        }
        return new String(a);
    }
}

运行结果如下:

1234
1432

img

123456
163452

img

如有帮助,请采纳,十分感谢!

运行不了具体什么情况。
程序有没有结束。