Area & Perimeter of a circle

 Area & Perimeter of a circle


Problem Description


Write a Java program to get the input as radius of a circle print the area and perimeter of a circle as output


Note:


Use double data type


and in the output statement use String.format("%.02f", variable name) for both area and Perimeter

Logic Test Case 1


Input (stdin)

7.5


Expected Output


47.10


176.63

Logic Test Case 2


Input (stdin)

5.76


Expected Output


36.17


104.18



CODE AREA


import java.io.*;

import java.util.Scanner;

public class TestClass {

public static void main(String[] args) { 

       Scanner s=new Scanner(System.in);

       double r=s.nextDouble();

       double pi=3.14;

       double a=pi*r*r;

       double p=2*pi*r;

       String n=String.format("%.2f",a);

       String m=String.format("%.2f",p);

       System.out.println(m);

       System.out.println(n);

       

       

}

}

Post a comment

0 Comments