We would like to write a program that displays the area and perimeter of a circle that has a radius of 5.5.
The following formula you can use:
perimeter = 2 times radius times pi area = radius times radius times pi
public class Main { public static void main(String[] args) { System.out.println("Perimeter = "); System.out.println(2 * 5.5 * 3.14159); System.out.println("Area = "); System.out.println(5.5 * 5.5 * 3.14159); } }
We can also use the constant from Math class.
public class Main { public static void main(String[] args) { double perimeter = perimeter(5.5); double area = area(5.5); System.out.println("perimeter: " + perimeter); System.out.println("area: " + area); }//from w w w . j a va 2 s .c om private static double perimeter(double radius) { return 2 * radius * Math.PI; } private static double area(double radius) { return radius * radius * Math.PI; } }