Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Science For Dummies

Authors: Lillian Pierson ,Jake Porway

2nd Edition

1119327636, 978-1119327639

More Books

Students also viewed these Databases questions