I am learning this simple code but I do not understand why b do not return the value of the division. For example I input 10 and 2 and it output for me 2 instead of 5.
Thanks for your time!
import java.util.Scanner;
class Throw_Exception{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a = 0;
do{
System.out.println("Input number A and B: ");
a = input.nextInt();
int b = input.nextInt();
input.close();
div(a,b);
System.out.println("The division is " + b);
}while (a != -1 );
}
static int div(int a, int b) throws ArithmeticException{
if(b == 0){
throw new ArithmeticException("Division by Zero");
}else{
b = a/b;
return b;
}
}
}