Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////
- // Ruslan Kaybyshev //
- // AP Comp Sci //
- // 10/13/2011 //
- //////////////////////
- // Find Circle Area //
- //////////////////////
- package pk1;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class CircleAreaFinder
- {
- public static void main(String[] args)
- {
- // Initialize method of getting input.
- Scanner scanner = new Scanner(System.in);
- // Initialize method of formatting.
- DecimalFormat format = new DecimalFormat("0.00");
- // Declare variables.
- double radius = 0; // circle radius
- double area = 0; // circle area
- double c = 0; // circle circumference
- // Get input
- System.out.println("Enter the radius of the circle: ");
- radius = scanner.nextDouble();
- if(radius>=0)
- {
- // Calculate the properties.
- area = Math.PI*radius*radius;
- c = Math.PI*2*radius;
- // Print outputs
- System.out.println("The area is: "+format.format(area));
- System.out.println("The circumference is: "+format.format(c));
- }
- else
- {
- System.out.println("Invalid Input!");
- }
- }
- }
Add Comment
Please, Sign In to add comment