Java

2. Write a Java program that calculates the volume of a the formulaV = r2h, where r is the radius of the circular base of the 2. Write a Java program that calculates the volume of a the formulaV = r2h, where r is the radius of the circular base of the cylinder and h is the cylinder’s height, both given in centimeters. The program will ask the user for the radius and height, and output the volume. The value of r is given by the constant Math.PI. (The Java language provides this constant as imported by default.) To perform the calculation, declare the input variables r and h to have type double. To calculate r2 just use r*r. Output the volume to two decimal places. See exercise 1 on how to format double values with decimal places. cylinder in cubic centimeters, using part of the package java.lang, which is automatically



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *