Area and Perimeter: Write a program that prints the area and perimeter of a circle with a radius of 5.5 using the formula: Perimeter = 2 * radius * PI Area = radius * radius * PI Use Math.PI for PI in your program.
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Solution:
Approach:
- Create a class circle
- In the main method declare the variables radius, area, perimeter of type double and initialize the radius =5.5
- There are 2 ways to use Math.PI in the code:
- Method 1:we can use as :
double area = Math.PI*radius*radius; //calculating area using Math.PI
double perimeter = 2*radius*Math.PI; // calculating perimeter using Math.PI
- Method 2 we can use by importing package as import static java.lang.Math.PI; and in the code we can write as :
double area = PI*radius*radius; //calculating area
double perimeter = 2*radius*PI; // calculating perimeter
- Finally printing the values i have rounded the values to 3 decimal places since the value was very big as:
System.out.format("%.3f",area); //printing area value that rounds to 3 decimal places
System.out.format("%.3f",perimeter); // printing perimeter value that rounds to 3 decimal places
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images