你的代码中有硬伤:String B = a.substring(2,4);
应该是英文的逗号(,)而不是中文的逗号(,)。
其实错误提示说的很清楚了。
楼主,我测了一下没有问题啊。你再试试
public class Test {
public static void main(String[] args)
{
String a = new String("hello, world");
String B = a.substring(2,4);
System.out.println(B);
}
}
有可能真的是你的2,4之间的逗号问题,得到b的值为ll.
。。。。。明显是逗号有问题(2,4);
中间要是英文的
就是逗号问题。