编写应用程序,从命令行传入两个整型数作为除数和被除数。要求程序中捕获NumberFormatException 异常和ArithmeticException 异常,而且无论在哪种情况下,“总是被执行”这句话都会在控制台输出
import java.util.Scanner;
public class TryError {
/*
* 1、编写应用程序,从命令行传入两个整型数作为除数和被除数。 要求程序中捕获NumberFormatException
* 异常和ArithmeticException 异常,而且无论在哪种情况下,“总是被执行”这句话都会在控制台输出。
*/
public TryError() {
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("please enter the first Number");
String string1 = scanner.next();
System.out.println("please enter the second Number");
String string2 = scanner.next();
int num1, num2;
try {
num1 = Integer.parseInt(string1);
num2 = Integer.parseInt(string2);
System.out.println(num1 / num2);
} catch (NumberFormatException | ArithmeticException e) {
e.printStackTrace();
} finally {
System.out.println("alaways doing ....");
}
}
}
分割线
博主为咯学编程:父母不同意学编程,现已断绝关系;恋人不同意学编程,现已分手;亲戚不同意学编程,现已断绝来往;老板不同意学编程,现已失业三十年。。。。。。如果此博文有帮到你欢迎打赏,金额不限。。。