You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Java/Java异常处理之try-catch之异常捕获.txt

28 lines
738 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import java.util.Scanner;
public class ExcTest {
public static void main(String[] args) {
// 请在Begin-End间编写代码
/********** Begin **********/
// 第一步:接收给定的整数
Scanner input=new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
int x;
// 第二步求给定两个数的商并捕获除数为0的异常
try{
x = a / b;
}
catch(Exception e){
{
System.out.println("除数不能为0");
}
}
if(b != 0){
System.out.println(a / b);
}
/********** End **********/
}
}