Hailstone Sequence
i'm currently working on the hailstone sequence program and i keep receiving this error "Exception in the thread "main" java.lang.outOfMemoryError : java heap space"
i have no idea how to fix it...plz help
here is the code
import java.util.ArrayList;
import java.util.Scanner;
public class Hailstone
{
public static ArrayList<Integer> findHailStone ( int seed ) // RETURN method
{
ArrayList list = new ArrayList();
list.add(seed);
while(seed != 1)
{
if(seed%2 == 0)
{
seed = seed/2;
list.add(seed);
}
else
{
seed = (seed*3)-1;
list.add(seed);
}
}
return list;
}
public static int findHighestValueInSequence ( ArrayList [] temp )
{
int high = 0;
for(int i=0; i<temp.length; i++)
{
for(int j=0; j><temp.size(); j++)
{
if(high >< ((Integer)temp.get(j)).intValue())
high = ((Integer)temp.get(j)).intValue();
}
}
return high;
}
public static void main(String [] args)
{
Scanner reader = new Scanner(System.in);
ArrayList [] list = new ArrayList[1000];
System.out.print("Input a number to find the hailstone" +
" sequence from 0 to that number: ");
int k = reader.nextInt();
for(int j=0; j<=k; j++)
{
list[j]=(findHailStone(j));
}
System.out.print("\nThe highest value in sequence is " +
findHighestValueInSequence(list));
for(int i=5; i<11; i++)
{
System.out.println(findHailStone(i));
}
}
}

