虽然Loop不工作

时间:2016-12-29 08:27:39

标签: java

请帮助我吗?我写了这段代码,但是不行。我不知道什么是坏事。

public class Whileloop {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    String equation ="+1x+1x+2=+1x+1x+6";
    String parts[] = equation.split("=");
    int no = 0;
    System.out.println(parts[no]);
    int helper = 5;
    for (parts[0].charAt(helper) != '-' || parts[0].charAt(helper) != '+';helper--) {
        System.out.println(helper);

    }
    System.out.println(helper);

  }
}

结果如下:

+1x+1x+2
5
4
3
2
1
0
  

线程“main”中的异常java.lang.StringIndexOutOfBoundsException:   字符串索引超出范围:-1         在java.lang.String.charAt(未知来源)         在Whileloop.main(Whileloop.java:12)

3 个答案:

答案 0 :(得分:0)

对我而言,它给出了预期的输出:

from collections import OrderedDict

L = dfc.apply(
    lambda x: OrderedDict(zip(x['A'].split(':'), x['B'].split(':'))), 1).tolist()
pd.DataFrame(L)

首先,它打印“部分”,最多为'='符号 + 1x + 1x + 2 。然后它进入循环,辅助值等于5.然后帮助器减1并显示4.最后它变为-1,从而给出IndexOutOfBound Exception。  你应该使用&&而不是||。

答案 1 :(得分:0)

helper将变为“-1”,因此charAt(-1)抛出异常,因为“-1”是无效的地方。你可以查看帮手> 0&& (你的条件)使它工作:)

答案 2 :(得分:0)

undefined reference to SCARD_CTL_CODE

输出: + 1X + 1X + 2 五 4 3 2 1 0

相关问题