Home Top Ad

Write a Java program to Compute Area and Circumference with formatting and standard I/O

Share:

Write a Java program to Compute Area and Circumference with formatting and standard I/O.

(SOURCE CODE)
import java.text.*;
import java.util.*;

class Circle
{
   public static void main(String[] args)
      {
          double PI = 3.14159;
          String TAB = "\t";
          String NEWLINE = "\n";
       double radius, area, circumference;
       Scanner scanner = new Scanner(System.in);
       DecimalFormat df = new DecimalFormat("0.000");
       System.out.println("Enter radius: ");

       radius = scanner.nextDouble( );
       area = PI * radius * radius;                       //compute the area and circumference
       circumference = 2.0 * PI * radius;

   System.out.println("Given Radius: " + TAB + df.format(radius) + NEWLINE +"Area: " + TAB + df.format(area) + NEWLINE +
   "Circumference: " + TAB + df.format(circumference));  //Display the results
     }
}

No comments