SentientStone
Member
Okay, I have finished most of my mini assignment from last week but I am unable to figure out how to define and use math.pi in my program. I need to write a function in java that calculates the area of a circle. I just need to know how I define Math.PI... I think.
Anyway, I just spent hours reading and doing some other assignment (not java) and I am in dire need of sleep as I have to wake up for class in say 3.5 hours or so.
Any help will be greatly appreciated. ;P
My current code:
class Function
{
public static void main(String args[])
{
int x = 11;
int y = 5;
int radius = 5;
int circleArea = 0;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
{
System.out.println("Sum of " + "i:" + i + " " + " and j:" + j + " equals " + addElements(i,j));
}
System.out.println( x + " divide by " + y + " has a remainder of " + findRemainder(x,y));
System.out.println();
System.out.println("The area of the circle is" + circleArea);
}
// this function add two numbers
public static int addElements(int a, int b)
{
int total = 0;
total = a + b;
return total;
}
// this function finds the remainder
public static int findRemainder(int c, int d)
{
int remainder = 0;
remainder = c%d;
return remainder;
}
// this function finds the area of a circle
public int findAreaCircle(int radius, Math.PI)
{
int circleArea = 0;
circleArea = (Math.PI*radius*radius);
return circleArea;
}
}
Anyway, I just spent hours reading and doing some other assignment (not java) and I am in dire need of sleep as I have to wake up for class in say 3.5 hours or so.
Any help will be greatly appreciated. ;P
My current code:
class Function
{
public static void main(String args[])
{
int x = 11;
int y = 5;
int radius = 5;
int circleArea = 0;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
{
System.out.println("Sum of " + "i:" + i + " " + " and j:" + j + " equals " + addElements(i,j));
}
System.out.println( x + " divide by " + y + " has a remainder of " + findRemainder(x,y));
System.out.println();
System.out.println("The area of the circle is" + circleArea);
}
// this function add two numbers
public static int addElements(int a, int b)
{
int total = 0;
total = a + b;
return total;
}
// this function finds the remainder
public static int findRemainder(int c, int d)
{
int remainder = 0;
remainder = c%d;
return remainder;
}
// this function finds the area of a circle
public int findAreaCircle(int radius, Math.PI)
{
int circleArea = 0;
circleArea = (Math.PI*radius*radius);
return circleArea;
}
}