I'm new Java and programming in general. I'm stuck on a problem in a course I'm taking and any help would be appreciated. We're covering catch blocks and the program needs to read two integers on the same line and divide the two. The two catch blocks are dividing by zero and not entering a number. The problem I'm running into, i cannot get the program to correctly read the two integers input.
package chapter9problem2;
import java.util.Scanner;
public class Chapter9Problem2 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
boolean done = false;
while (!done)
{
try{
System.out.println("Enter two numbers. Please leave a space between the numbers. I will compute the ratio.");
String input = keyboard.nextLine();
String[] numbersStr = input.split(" ");
int[] numbers = new int[ numbersStr.length ];
for ( int i = 0; i < numbersStr.length; i++ )
{
numbers[i] = Integer.parseInt( numbersStr[i] );
}
System.out.println("");
System.out.println("The ratio r is: "+(numbers[1]/numbers[2]));
}
catch (ArithmeticException e)
{
System.out.println("There was an exception: Divide by zero... Try again.");
}
catch (Exception e) {
System.out.println("You must enter an Integer. ");
}
continue;
}
}
}