これを行う方法はありますか?
//Example function taking in first and last name and returning the last name.
public void lastNameGenerator() throws Exception{
try {
String fullName = JOptionPane.showInputDialog("Enter your full name");
String lastName = fullName.split("\\s+")[1];
catch (IOException e) {
System.out.println("Sorry, please enter your full name separated by a space.")
//Repeat try statement. ie. Ask user for a new string?
}
System.out.println(lastName);
代わりにスキャナーを使用できると思いますが、例外をキャッチした後に try ステートメントを繰り返す方法があるかどうかに興味がありました。