(Java)求大佬帮忙写一下
import java.util.*;
public class interView {
public static void main(String[] args) {
System.out.println("输入第一个String类型:");
String a = null;
Scanner cin = new Scanner(System.in);
while (cin.hasNext()) {
a = cin.nextLine();
break;
}
System.out.println("输入第二个String类型:");
String b = null;
Scanner cin1 = new Scanner(System.in);
while (cin.hasNext()) {
b = cin.nextLine();
break;
}
Remainder ss = new Remainder();
ss.getRemainder(a, b);
}
public static class Remainder {
public void getRemainder(String a, String b) {
int i = Integer.parseInt(a);
int j = Integer.parseInt(b);
try {
int n = i / j;
System.out.println("两个数的商:" + n);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
结果如下: 1、NumberFormatException
2、ArithmeticException
3、正常
2020-04-02
private static void quotient(String num1, String num2) {
try {
int n1 = Integer.parseInt(num1);
int n2 = Integer.parseInt(num2);
System.out.println("商为:" + n1 / n2);
} catch (NumberFormatException e1) {
System.out.println("NumberFormatException");
} catch (ArithmeticException e2){
System.out.println("ArithmeticException");
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String num1 = scanner.next();
String num2 = scanner.next();
quotient(num1, num2);
}
}