This program is used to get the array size and then store some values and get the highest value that the user typed.
I'm using array and I don't know what's the problem. When in runtime a window pops out and it say ArrayIndexOutofBoundsException. Please help im new in java and im also a student.
import java.util.*; import javax.swing.*; public class zy { public static void main(String args[]) { String input,input2; int bck,num,h=0,test=0; do{ input=JOptionPane.showInputDialog(null,"Enter Array Size","Array Size",JOptionPane.INFORMATION_MESSAGE); num=Integer.parseInt(input); for(int ctr=1;ctr<num+1;ctr++) { input2=JOptionPane.showInputDialog(null,"Enter Number " +ctr,"Numbers to test" ,JOptionPane.INFORMATION_MESSAGE); int num2=Integer.parseInt(input2); int array[]=new int[num2]; if (test==0) { h=array[num2]; test=1; } else if (array[num2]>h) { h=array[num2]; } } JOptionPane.showMessageDialog(null,"Highest No: " +h,"Highest Number",JOptionPane.INFORMATION_MESSAGE); bck=JOptionPane.showConfirmDialog(null,"Do you want to try again?","CONFIRMATION",JOptionPane.YES_NO_OPTION); h=0; test=0; }while(bck==JOptionPane.YES_OPTION); } }