Advertisement
cgorrillaha

Area/Circ

Sep 15th, 2021
1,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. //**********************************************************
  2. //  Circle.java
  3. //
  4. //  Print the area of a circle with two different radii
  5. //**********************************************************
  6.  
  7. public class Circle
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         //final double PI = 3.14159;
  12.  
  13.         //declarations
  14.         int radius = 10;
  15.         int radius2 = 20;
  16.         //calculations
  17.         double area = Math.PI * radius * radius;
  18.  
  19.         double circ = Math.PI*2*radius;
  20.  
  21.         System.out.println("The area of a circle with radius " + radius +
  22.                 " is " + area);
  23.         System.out.println("The circumference of a circle with radius " + radius +
  24.                 " is " + circ);
  25.  
  26.         //reassignment
  27.  
  28.         //calculations
  29.         double area2 = Math.PI * radius2 * radius2;
  30.         double circ2 = Math.PI*2*radius2;
  31.  
  32.         //outputs
  33.  
  34.         System.out.println("The area of a circle with radius " + radius2 +
  35.                 " is " + area2);
  36.         System.out.println("The circumference of a circle with radius " + radius2 +
  37.                 " is " + circ2);
  38.  
  39.         double areaGrowthFactor=area2/area;
  40.         double circGrowthFactor=circ2/circ;
  41.  
  42.         System.out.println("When the radius is doubled, area grows by a factor of: "+areaGrowthFactor);
  43.         System.out.println("When the radius is doubled, circumference grows by a factor of: "+circGrowthFactor);
  44.  
  45.  
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement