java 保留小数点后2位0
oxeozsa2013.06.14浏览7564次分享举报
/**
* Write a description of class Cylinder here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Cylinder
{
// instance variables - replace the example below with your own
private double radius;
private double height;
/**
* Constructor for objects of class Cylinder
*/
public Cylinder(double r, double h)
{
// initialise instance variables
radius = r;
height = h;
double newBase = base();
System.out.println(" the value of the base is: " + newBase);
double newCirc = circumference();
System.out.println(" the value of the Circ is: " + newCirc);
}
public double base()
{
double answer= Math.PI * radius * radius;
return answer;
}
public double circumference()
{
double answer=Math.PI * radius;
return answer;
}
}
保留2位小数