求大神解答!!!
谁能告诉我5/2,这个除数怎么传递,我的怎么总是5/0,学者后面忘着前面......
import java.util.InputMismatchException; import java.util.Scanner; import javax.print.attribute.standard.Finishings; public class Abc { int num=0; public static void main(String[] args) { // TODO Auto-generated method stub int num=0; Abc abc=new Abc(); System.out.println("请输入一个值:"); try{ System.out.println("5/"+num+"结果为:"+abc.mat()); }catch (ArithmeticException e) { // TODO: handle exception System.out.println("输入错误:: "+e); } catch (InputMismatchException e) { // TODO: handle exception System.out.println("请输入整数 :"+e); } finally { } } public int geter() throws InputMismatchException { Scanner scanner=new Scanner(System.in); num=scanner.nextInt(); scanner.close(); return num; } public int mat() { return 5/geter(); } }
请输入一个值:
2
5/0结果为:2