Java Area Calculation

Inquisitor said:
Something along these lines?
Code:
public static double calculateArea(double startLength, int squareCount, double increment)
{
	double totalArea = 0;
	double length = startLength;
	for (int i = 0; i < squareCount; i++, length += increment)
	{
		totalArea += length * length;
	}
	
	return totalArea;
}

Thanks, I had thought that it would be some sort of loop.

I have been having a go with that one, cant quite get it to work though. the return totalarea part is showing errors in the compiler at the moment. But I will keep trying.

And for the record its not coursework, its an example I have been given to practise on before getting the proper assignment in about 3 weeks time.

This work isnt being marked or assessed its simply practise for me :p (and my god do I need it!!)
 
Back
Top Bottom