java 保留小数点后2位
/***WriteadescriptionofclassCylinderhere.**@author(yourname)*@version(aversionnumbero...
/**
* 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位小数 展开
* 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位小数 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询