the program works the way i want it to except for the inputmismatchexception.
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Exception {
public static void main(String[] args) throws IOException {
int num = 100;
int tempNum;
int index;
String[] strArray = new String[num];
int[] numArray = new int [num];
File tempo = new File ("exceptionData.txt");
Scanner file = new Scanner(tempo);
for( int i = 0; i < numArray.length; i++)
{
strArray[i] = file.next();
numArray[i] = Integer.parseInt(strArray[i]);
}
Scanner input = new Scanner (System.in);
while(input.hasNextInt())
{
index = input.nextInt();
try
{
if(index == -1)
{
System.exit(0);
}
System.out.print(index + ": " + numArray[index] + ", ");
}
catch(ArrayIndexOutOfBoundsException ex)
{
System.out.println("\nException: " + index + " is Out of bounds");
}
catch (InputMismatchException ex)
{
System.out.println("\nException: Enter an integer (-1 to quit)\n");
}
}
}
}
OUTPUT should look like this
enter numbers: 0 2 3 9 -100 -10 A
0: 412, 2: 201, 3: 397, 9: 750,
Exception: -100 is Out of Bounds
Exception: -10 is Out of Bounds //array indexoutof bounds
Exception: Enter an integer (-1 to quit) //inputmismatch