控制台输入相关数据,并计算出结果,类似控制台计算器
package cn.com.lyong.day10;
import java.util.Scanner;
public class TestException {
public static void main(String[] args) {
try {
int a =0;
int b =0;
Scanner sc = new Scanner(System.in);
System.out.println("输入除数a为:");
a = sc.nextInt();
System.out.println("输入被除数b为:");
b = sc.nextInt();
System.out.println("计算结果为:"+a/b);
} catch (Exception e) {
System.out.println("除数不能为0");
}
}
}