Java 测试减号后的字符是否为数字
我有这个字符串Java 测试减号后的字符是否为数字,java,Java,我有这个字符串9$-2-。我想测试-中的下一个是否是数字 if (ch == '-') { if (ch != input.length() - 1) { char next = input.charAt(j + 1); if ((next >= '0' && next <= '9') || next == '.') temp = temp + ch; } } 什么是ch——输入字符串中的字符或
9$-2-
。我想测试-
中的下一个是否是数字
if (ch == '-') {
if (ch != input.length() - 1) {
char next = input.charAt(j + 1);
if ((next >= '0' && next <= '9') || next == '.')
temp = temp + ch;
}
}
什么是
ch
——输入字符串中的字符或字符的索引(位置)?第一行假定为前者,第二行假定为后者。也许你想要if(j!=input.length()-1)
。变量j
来自哪里?char next=input.charAt(j+1);这种情况是错误的非常长的应用程序!问题不在j
我没有看到您的其余代码,但是您可能想研究正则表达式。while循环在哪里?
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 8
at java.lang.String.charAt(String.java:658)
at ParsePost.doParse(ParsePost.java:24)
at InfixApp.main(InfixApp.java:20)