java中的如果使用string a=string new("hello");,那么是不是就不能用substring?

2025-03-10 13:05:01
推荐回答(4个)
回答1:

你的代码中有硬伤:String B = a.substring(2,4);
应该是英文的逗号(,)而不是中文的逗号(,)。

其实错误提示说的很清楚了。

回答2:

楼主,我测了一下没有问题啊。你再试试
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.

回答3:

。。。。。明显是逗号有问题(2,4);
中间要是英文的

回答4:

就是逗号问题。