Make This Java code more efficient : <p><em>This Code is work but i got error at last after the execution of my code i.e Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at AddNum.main(AddNum.java:24), can any one fix this issue or make it more efficient to use.</em></p>

<pre><code>import java.util.Scanner;
public class AddNum {
public static void main(String args[])
{
    int num1,num2,sum,i=0;
    int[] arr =new int[5];
    System.out.println("Enter Any two number to Add and See magic");
    Scanner scan = new Scanner(System.in);
    num1 = scan.nextInt();
    num2 = scan.nextInt();
    sum = num1 + num2;
    System.out.println("The Sum of "+num1+" and "+num2+" is = "+sum );
    do
    {
        arr[i++]=sum%10;
        sum/=10;
    }while(sum&gt;0);
    for(int p=i;p&gt;=0;p--)
    {
        mag(arr[p-1]);
    }
}
public static void mag(int sum)
{
    switch(sum){
        case 0:
            System.out.println("    00000");
            System.out.println("   00   00");
            System.out.println("  000   000");
            System.out.println("  000   000");
            System.out.println("  000   000");
            System.out.println("  000   000");
            System.out.println("  000   000");
            System.out.println("   00   00");
            System.out.println("    00000");
            break;

        case 1:
        System.out.println("      11");
        System.out.println("     111");
        System.out.println("   1 111");
        System.out.println("     111");
        System.out.println("     111");
        System.out.println("     111");
        System.out.println("     111");
        System.out.println("     111");
        System.out.println("    11111");
        break;
        case 2:
            System.out.println("    2222");
            System.out.println("  22    22");
            System.out.println("  2     222");
            System.out.println("        22");
            System.out.println("       22");
            System.out.println("     22");
            System.out.println("   222    2");
            System.out.println("  222    22");
            System.out.println("  222222222");
            break;
        case 3:
            System.out.println("    3333");
            System.out.println("  33   333");
            System.out.println("  3     333");
            System.out.println("       33");
            System.out.println("     333");
            System.out.println("       33");
            System.out.println("  3     333");
            System.out.println("  33   333");
            System.out.println("    3333");
            break;
        case 4:
            System.out.println("        44");
            System.out.println("      4444");
            System.out.println("     4 444");
            System.out.println("    4  444  ");
            System.out.println("   4   444");
            System.out.println("  4444444444");
            System.out.println("       444  ");
            System.out.println("       444");
            System.out.println("      44444");
            break;
        case 5:
            System.out.println("  5555555");
            System.out.println("  555    5");
            System.out.println("  555");
            System.out.println("  555");
            System.out.println("  555555");
            System.out.println("       555");
            System.out.println("  5     555");
            System.out.println("  55   555");
            System.out.println("    5555");
            break;
        case 6:
            System.out.println("    66666");
            System.out.println("   66    66 ");
            System.out.println("  666     6");
            System.out.println("  666");
            System.out.println("  6666666");
            System.out.println("  666   666");
            System.out.println("  666    666");
            System.out.println("   66   666");
            System.out.println("    66666");
            break;
        case 7:
            System.out.println("   777777777");
            System.out.println("  77     777");
            System.out.println("  7     777");
            System.out.println("       77");
            System.out.println("      77");
            System.out.println("     77");
            System.out.println("    777");
            System.out.println("   777");
            System.out.println("   777");
            break;
        case 8:
            System.out.println("    888888");
            System.out.println("   888  888");
            System.out.println("   888  888");
            System.out.println("    888888");
            System.out.println("   888  888");
            System.out.println("  888    888");
            System.out.println("  888    888");
            System.out.println("   888  888");
            System.out.println("     8888");
            break;
        case 9:
            System.out.println("    99999");
            System.out.println("   999 999");
            System.out.println("  999   999");
            System.out.println("  999   999");
            System.out.println("    9999999");
            System.out.println("        999");
            System.out.println("  9     999");
            System.out.println("  99   999");
            System.out.println("    9999");
            break;





    }
} }
</code></pre>
