import java.util.Random;
import java.util.Scanner;

// Dealing with run time errors

public class RuntimeExample
{
    public static void main(String [] args)
    {
	int x;
	int y;
	int z;
	int i;
	Random aGenerator = new Random();
	// case 1: division by zero check inputs to calculation
	for (i = 0; i < 100; i++)
	{
	    x = aGenerator.nextInt(10);
	    y = aGenerator.nextInt(10);
	    z = x / y;
	}
	
	// case 2: null pointer exception, no object yet!
	String aString = null;
	aString.compareToIgnoreCase("password");
	
	// case 3: array bounds
	int [] array = {1,2,3,4,5,6,7,8,9,0};
	int index;
	Scanner in = new Scanner(System.in);
	System.out.print("Enter index of element to access: ");
	index = in.nextInt();
	System.out.println(array[index]);
    }
}
