Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //class work
- import java.util.Scanner; //importing scanner
- public class number5 { //program begins
- public static void main(String[] args) {
- //5. Write an application that prompts the user for the radius of a circle and uses a method called circleArea to calculate the area of the circle.
- Scanner input = new Scanner (System.in); //scanner declaration
- //variable declaration
- double radius;
- //input statement for the user to enter the radius
- System.out.println("Radius of a circle: ");
- radius = input.nextDouble();
- //output statement to display the area
- System.out.println("The area of a circle is: " +circleArea(radius));
- }
- public static double circleArea(double radius) {
- double area; //variable declaration
- final double pi = 3.14;
- area = pi * radius * radius; //calculating the area
- return area;
- } //method ends
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement