嗨,我是 Java 编程新手。我想编写一个获取用户的名字和姓氏首字母的java程序。我的代码是:
public class MyProgram {
public void start() {
String name = getNameFromUser();
char firstNameInitials = getInitials(name);
char surnameInitials = getInitials(name);
printInitials(firstNameInitials, surnameInitials);
}
private String getNameFromUser() {
System.out.print("Please enter your name: ");
String name = Keyboard.readInput();
return name;
}
private char getInitials(String name) {
char firstNameInitials = name.charAt(0);
int indexOfSpace = name.indexOf(" ");
char surnameInitials = name.charAt(indexOfSpace + 1);
return firstNameInitials; surnameInitials;
}
private void printInitials(String firstNameInitials, String surnameInitials){
System.out.print("your initials are: " + firstNameInitials +". " + surnameInitials +".");
}
}
我收到一条错误消息,我不知道这意味着什么:
Error: not a statement.
错误似乎在第 18 行,在 return 语句处。我试图修复它但失败了。请问有什么建议可以解决这个问题吗?