package chapter12;
import java.util.Scanner;
// a)编写应用程序EcmDef.java,接收命令行的两个参数(整数),计算两数相除。
// b)计算两个数相除,要求使用方法cal(int n1, int n2)
// c)对数据格式不正确、缺少命令行参数、除0进行异常处理。
//和老师想法不一样的地方:1.通过命令行接收,意思是直接从args[]里面来接收,不通过Scanner.再ieda中使用args[],
// 必须配置参数,这就相当于输入了
// 2.可以多次catch,对于一个try来说,这是一个误区,以为只能有一个catch
public class EcmDef {
public static void main(String[] args){
Scanner sc1 = new Scanner(System.in);//使用了两个Scanner对象,但是应该要先关闭上一个才能开下一个,要不然进不去
Scanner sc2 = new Scanner(System.in);
//System.out.println("请输入数字:");
try{
//System.out.println("请输入数字:");
int n1 = Integer.getInteger(sc1.next());
//System.out.println("请输入数字:");
int n2 = Integer.getInteger(sc2.next());
int reslut = cal(n1,n2);
}catch (Exception e){
System.out.println("发生错误");
}
}
public static int cal(int n1,int n2){
return n1 / n2;
}
}
08-07
240
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-04
332
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-02
1114
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-30
712
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)