public class Main { public static void main(String[] args) { String a = "12"; String b = "x9"; // TODO: 捕获异常并处理 int c = stringToInt(a); int d = stringToInt(b); System.out.println(c * d); } static int stringToInt(String s) { try { return Integer.parseInt(s); } catch (Exception e) { // TODO: handle exception System.out.println("字符串:" + s +"非全数字,不能转换为整形 " ); return 0; } } }
Sign in to make a reply
明明love0