Java String Insertion错误

时间:2013-03-08 04:48:55

标签: java string random

每当我运行此方法时 -

stringBot = bot.getText();
        stringTop = top.getText();
        intBot = stringBot.length();
        intTop = stringTop.length();
        String stringMove = "";
        r=0+Math.random()*intTop;
        if (intBot > intTop &&intBot>1 ){
              lastBot = stringBot.charAt(intBot-1);




 //stringMove =stringTop.substring(0,(int) r) + lastBot + stringTop.substring(intTop+1);



              top.setText(stringTop);
              stringBot=stringBot.substring(0,intBot-1);

              bot.setText(stringBot);
        }
        else if (intTop >= intBot &&intTop>1 ){
              lastTop = stringTop.charAt(intTop-1);
              stringMove = stringMove+lastTop;
              top.setText(stringBot+stringMove);
              stringTop=stringTop.substring(0,intTop-1);

              top.setText(stringTop);
        }

我在评论部分收到错误,请帮助我。该错误并不完全是语法,因为当我编译它时,直到我单击左键时实际运行该方法时才识别错误。然后它给了我一个终端窗口

1 个答案:

答案 0 :(得分:0)

stringTop.substring(intTop+1) intTop = stringTop.length();。{。} 所以你应该有例外,因为intTop+1>长度为stringTop