mirror of
https://github.com/Dichgrem/Java.git
synced 2026-02-05 02:51:57 -05:00
update:demo7
This commit is contained in:
24
com/study/demo7/DivisionCalculator.java
Normal file
24
com/study/demo7/DivisionCalculator.java
Normal file
@@ -0,0 +1,24 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user