Question: How to add the following to existing java code Add a function (areaCircle) to calculate an area of circle, and then in the main( )

How to add the following to existing java code

Add a function (areaCircle) to calculate an area of circle, and then in the main( ) function call the function to calculate the area of a circle with radius of 5, and output the result. You can define a constant variable called static final double PI = 3.14159 (or just use Math.PI in the default package of java.lang in the Java API library) to calculate the area (PI*radius*radius).

----------------------------------------------------------------------------------------------------------------------------

// This program shows how to design a simple function statement.

public class Function

{

public static void main(String args[])

{

int x = 11;

int y = 5;

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));

}

// 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;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!