我正在为课堂写一个直接的机场航站楼风格的课程.我超出了作业范围并"尝试"使用Try/Catch块......
然而Java现在就是那个人.
问题是当有人在下面的代码中输入一个非字母时它没有捕获然后返回它捕获的try块...
为什么?
编辑 - 此外,containsOnlyLetters方法有效,除非有人认为可能是错误?
System.out.println("\nGood News! That seat is available");
try
{//try
System.out.print("Enter your first name: ");
temp = input.nextLine();
if (containsOnlyLetters(temp))
firstName = temp;
else
throw new Exception("First name must contain"
+ " only letters");
System.out.print("Enter your last name: ");
temp = input.nextLine();
if (containsOnlyLetters(temp))
lastName = temp;
else
throw new Exception("Last name must contain"
+ " only letters");
}//end try
catch(Exception e)
{//catch
System.out.println(e.getMessage());
System.out.println("\nPlease try again... ");
}//end catch
passengers[clients] = new clientInfo
(firstName, …Run Code Online (Sandbox Code Playgroud)