Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //**********************************************************
- // Circle.java
- //
- // Print the area of a circle with two different radii
- //**********************************************************
- public class Circle
- {
- public static void main(String[] args)
- {
- //final double PI = 3.14159;
- //declarations
- int radius = 10;
- int radius2 = 20;
- //calculations
- double area = Math.PI * radius * radius;
- double circ = Math.PI*2*radius;
- System.out.println("The area of a circle with radius " + radius +
- " is " + area);
- System.out.println("The circumference of a circle with radius " + radius +
- " is " + circ);
- //reassignment
- //calculations
- double area2 = Math.PI * radius2 * radius2;
- double circ2 = Math.PI*2*radius2;
- //outputs
- System.out.println("The area of a circle with radius " + radius2 +
- " is " + area2);
- System.out.println("The circumference of a circle with radius " + radius2 +
- " is " + circ2);
- double areaGrowthFactor=area2/area;
- double circGrowthFactor=circ2/circ;
- System.out.println("When the radius is doubled, area grows by a factor of: "+areaGrowthFactor);
- System.out.println("When the radius is doubled, circumference grows by a factor of: "+circGrowthFactor);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement