Discuss / Java / 打卡作业,互相学习,关注微信公众号【程序员明明】

打卡作业,互相学习,关注微信公众号【程序员明明】

Topic source

明明love0

#1 Created at ... [Delete] [Delete and Lock User]
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;
		}
		
	}
}

  • 1

Reply