while(list.size() != 0 )
{
for(int i=0 ;i<list.size();i++)
{
//if current element is smaller than firat update first & second
if(list.get(i) < first)
{
second = first;
first = list.get(i);
j = i;
}
else if(list.get(i)<second && list.get(i) != first)
{
second= list.get(i);
k = i;
}
}
list.remove(j);
list.remove(k);
list.add(first+second);
for(int inte :sortedArray)
{
sortedArray.add(first+second);
}
}
Collections.sort(sortedArray);
Here in this code Im getting an error!!!
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index:2,Size: 2
Please anybody help me where it is going wrong! Thanks in advance.