hi people, I am a newbie to Java OOP,i cam across this example in a text book, but i just cldn't understand how the area is calculated.
hope that someone can explain this simple problem to me
the code is:
public class TestPassingObject
{
// Main method
public static void main ( String [ ] args )
{
// Create a Circle object with default radius 1
Circle myCircle = new Circle ( );
// Print areas for radii 1, 2, 3, 4 and 5
int n = 5;
printAreas ( myCircle, n );
// See myCircle.radius and times
System.out.println ( " \n " + " Radius is " + myCircle.radius );
System.out.println ( " n is " + n );
}
// Print a table of areas for radius
public static void printAreas ( Circle c, int times )
{
System.out.println ( " Radius \t \t Area " );
while ( times >= 1)
{
System.out.println ( c.radius + " \t \t " + c.findArea ( ) );
c.radius ++;
times--;
}
}
}
and the results are :
Radius Area
1.0 3.14159
2.0 12.56636
3.0 28.27431
4.0 50.26544
5.0 78.53975
Radius is 6.0
n is 5
thanks in advance : )