Advertisement
thotfrnk

methods5.java

Dec 7th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. //class work
  2. import java.util.Scanner; //importing scanner
  3. public class number5 { //program begins
  4.     public static void main(String[] args) {
  5.  
  6.         //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.
  7.  
  8.         Scanner input = new Scanner (System.in); //scanner declaration
  9.        
  10.         //variable declaration
  11.  
  12.         double radius;
  13.  
  14.         //input statement for the user to enter the radius
  15.         System.out.println("Radius of a circle: ");
  16.         radius = input.nextDouble();
  17.  
  18.         //output statement to display the area
  19.         System.out.println("The area of a circle is: " +circleArea(radius));
  20.     }
  21.  
  22.     public static double circleArea(double radius) {
  23.         double area; //variable declaration
  24.         final double pi = 3.14;
  25.         area = pi * radius * radius; //calculating the area
  26.         return area;
  27.     } //method ends
  28. } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement