我的程序似乎仅针对此特定输入生成超出范围错误的字符串索引。相同的代码适用于其他输入。将在下面添加输出屏幕截图和代码。我四处搜索 - 这个错误只出现在单个输入的事实使得它很难解决。
int ind,len,vallen,amount,credits = 0;
String credit;
String value,item;
float oneamount;
// System.out.println("Credit Assignment");
ind=input.indexOf("is");
credit = input.substring(0, ind-1);
// System.out.println(credit);
//Seperate the Quantity and Item Name from the String
len = credit.length();
vallen= credit.lastIndexOf(" ");
value= credit.substring(0,vallen); //**Line 59**
item = credit.substring(vallen,len).trim();
System.out.println(value);