程序检查字符串中的第一个字符是否是标点符号,如果是,则删除该字符并返回新字。检查字符是否为标点符号
public static String checkStart(String word){
char [] punctuation = {'.' , ',' , ';' , ':', '?' , '!' , '"' , '\'' , ')' , '('};
int i;
for (i = 0; i < punctuation.length;i++){
if(word.charAt(0) == punctuation[i]){
word = word.substring(1);
}
}
return word;
}
为什么不起作用?
这里是方法调用者
public static String[] removePunctuation(String [] words){
int i, j;
for (i = 0; i < words.length;i++){
words[i] = checkStart(words[i]);
}
return words;
}
}
看到你的标点符号数组的问题是与此。 – sumanta
什么是不工作?你有错误吗? – furkle
该程序将运行,但它会给出NullPointerException异常 并且它不会删除第一个字符,adasd仍将是asdasd – newbie