我正在编写一个从句子中删除一个字符的java程序。我收到一条错误消息:对于 java.Lang.String 类型,方法 charAt(int) 未定义。[第 35 行]
任何建议这意味着什么。
public class Ex1Program {
public void start() {
String sentence = getSentenceFromUser();
int randomPosition = getRandomPosition(sentence);
printCharacterToBeRemoved(sentence, randomPosition);
String changedSentence = removeCharacter(sentence, randomPosition);
printNewSentence(changedSentence);
}
private String getSentenceFromUser() {
System.out.print("Enter a sentence :");
String sentence = Keyboard.readInput();
return sentence;
}
private int getRandomPosition(String sentence) {
int randomPosition = (int)(Math.random() * 14) +1;
return randomPosition;
}
private void printCharacterToBeRemoved(String sentence, int randomPosition) {
System.out.print("Removing " + sentence.charAt(randomPosition) + " from position " + randomPosition);
}
private String removeCharacter(String sentence, int randomPosition) {
String changedSentence = sentence.trim().CharAt(randomPosition);
return changedSentence;
}
private void printNewSentence(String changedSentence) {
System.out.print("New sentence is " + changedSentence);
}
}