mirror of
https://github.com/Dichgrem/Java.git
synced 2026-02-05 01:11:57 -05:00
25 lines
761 B
Java
25 lines
761 B
Java
package com.study.demo7;
|
|
|
|
import java.util.Scanner;
|
|
|
|
public class DivisionCalculator {
|
|
public static void main(String[] args) {
|
|
Scanner scanner = new Scanner(System.in);
|
|
try {
|
|
System.out.print("请输入第一个整数 a: ");
|
|
int a = Integer.parseInt(scanner.nextLine());
|
|
System.out.print("请输入第二个整数 b: ");
|
|
int b = Integer.parseInt(scanner.nextLine());
|
|
int result = a / b;
|
|
System.out.println("结果: " + result);
|
|
} catch (ArithmeticException e) {
|
|
System.out.println("错误: 除数不能为 0");
|
|
} catch (NumberFormatException e) {
|
|
System.out.println("错误: 请输入有效的整数");
|
|
} finally {
|
|
System.out.println("计算结束");
|
|
}
|
|
scanner.close();
|
|
}
|
|
}
|