Q:

Java program to find the Surface Area and volume of the cylinder

0

Java program to find the Surface Area and volume of the cylinder

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will read radiusheight from the user and calculate the area, volume of the cylinder.

Program/Source Code:

The source code to find the Surface Area and volume of the cylinder is given below. The given program is compiled and executed successfully.

// Java program to find the Surface Area 
// and volume of the cylinder

import java.util.Scanner;

public class Main {
  static float calcuateVolumeOfCylinder(float radius, float height) {
    float result = 0.0F;
    result = 3.14F * radius * radius * height;
    return result;
  }

  static float calcuateAreaOfCylinder(float radius, float height) {
    float result = 0.0F;
    result = 2 * 3.14F * radius * (radius + height);
    return result;
  }

  public static void main(String[] args) {
    Scanner SC = new Scanner(System.in);

    float radius = 0;
    float height = 0;
    float volume = 0;
    float area = 0;

    System.out.printf("Enter the radius: ");
    radius = SC.nextFloat();

    System.out.printf("Enter the height: ");
    height = SC.nextFloat();

    volume = calcuateVolumeOfCylinder(radius, height);
    area = calcuateAreaOfCylinder(radius, height);

    System.out.printf("Volume of Cylinder is: %f\n", volume);
    System.out.printf("Surface area of Cylinder is: %f\n", area);
  }
}

Output:

Enter the radius: 3
Enter the height: 7
Volume of Cylinder is: 197.820007
Surface area of Cylinder is: 188.399994

Explanation:

In the above program, we imported the "java.util.Scanner" package to read input from the user. And, created a public class Main. It contain three static methods calcuateVolumeOfCylinder()calcuateAreaOfCylinder() and main().

The calcuateVolumeOfCylinder()calcuateAreaOfCylinder() methods are used to calculate the volume and area of the Cylinder based on given radius and height.

The main() method is an entry point for the program. And, we read radiusheight from the user using the Scanner class. Then we calculated the volume, area of the Cylinder using calcuateVolumeOfCylinder()calcuateAreaOfCylinder() methods, and printed the result.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now