Cylinder volume

 Cylinder volume

Problem Description


(Compute the volume of a cylinder)


Write a program that reads in the radius and length of a cylinder and computes the area and volume using the following


formulas:


area = radius * radius * pi

volume = area * length


Assign PI value as 3.14

Logic Test Case 1


Input (stdin)

12


34


Expected Output


452.16


15373.44

Logic Test Case 2


Input (stdin)

3


5


Expected Output


28.26


141.30



Code Area

import java.io.*;

import java.util.*;

import java.math.*;

public class TestClass {

public static void main(String[] args) { 

      Scanner s=new Scanner(System.in);

       double pi=3.14;

       double radius=s.nextDouble();

       double length=s.nextDouble();

       double area=radius*radius*pi;

       double volume=area*length;

       System.out.println("" +area);

       String str1=String.format("%.2f",volume);

       System.out.println(str1);

}

}

Post a comment

0 Comments