I was finding out highest prime factor which divides num, as shown in program, there\'s a issue with array and
arr[j] = i;
j++;
Excepti
By creating array arr[] = {j}, you have created an array which contains simply j, or 1. That means the length of the array is 1, because it contains 1 element. Thus, arr[1] is out of bounds. Java does not dynamically resize arrays, so you must create a sufficiently large array to contain all of the data you plan to hold. Either that or use something like an ArrayList, which is dynamically resizeable.