class address
{
String address;
String newaddr = address.trim();
final int ziplength =4;
String input;
Scanner in = new Scanner(System.in);
String temp = in.next();
String zipcode = input.substring(input.length()-ziplength);
try **//illegal start type error**
{
Integer.parseInt(zipcode);
System.out.println("PO is: "+zipcode);
}
catch( Exception e) **//illegal start type error**
{
System.err.println("Last 4 chars are not a number.");
}
}
此代码段从字符串中提取最后四个字符,并查看它们是否为邮政编码.
我评论了在NetBeans中报告“非法启动类型错误”的要点.
我想知道在创建类时是否不能使用try-catch?或者,这堂课错过了吗?
我尝试搜索stackoverflow.但是我仍然感到困惑.这里是一些链接.