class Trangle
{ double sideA,sideB,sideC,area,length; boolean boo; public Trangle(double a,double b,double c)
{
a=sideA; b=sideB; c=sideC;
if(a+b>c && a+c>b && a+c>b)
{
boo=true;
}
else
{
boo=false;
}
}
double getLength()
{
return sideA+sideB+sideC;
}
public double getArea()
{
if(boo)
{
double p=(sideA+sideB+sideC)/2.0;
area=Math.sqrt(p*(p-sideA)*(p-sideB)*(p-sideC)) ;
return area;
}
else
{
System.out.println("不是一个三角形,不能计算面积");
return 0;
}
}
public void setABC(double a,double b,double c)
{
a=sideA; b=sideB; c=sideC;
if(a+b>c && a+c>b && a+c>b)
{
boo=true;
}
else
{
boo=false;
}
}
}
class Lader
{
double above,bottom,height,area;
Lader(double a,double b,double h)
{
a=above;b=bottom;h=height;
}
double getArea()
{
return (above+bottom)*height/2;
}
}
class Circle
{
double radius,area;
Circle(double r)
{
r=radius;
}
double getArea()
{ return Math.PI *radius*radius;
}
double getLength()
{
return 2*Math.PI*radius;
}
void setRadius(double newRadius)
{
radius=newRadius;
}
double getRadius()
{
return radius;
}
}
public class AreaAndLength
{
public static void main(String args[])
{
double length,area;
Circle circle=null;
Trangle trangle;
Lader lader;
circle=new Circle(10);
trangle=new Trangle(3,4,5);
lader=new Lader(3,4,5);
length= circle.getLength();
System.out.println("圆的周长:"+length);
area=circle.getArea();
System.out.println("圆的面积:"+area);
length= trangle.getLength();
System.out.println("三角形的周长:"+length);
area=trangle.getArea();
System.out.println("三角形的面积:"+area);
area=lader.getArea();
System.out.println("梯形的面积:"+area);
trangle.setABC(12, 34, 1);
area=trangle.getArea();
System.out.println("三角形的面积:"+area);
length= trangle.getLength();
System.out.println("三角形的周长:"+length);
}
}
这个代码的作用是在你程序所在的盘下生成文件,你把程序放在C盘下运行就生成C盘下的文件。
如果想生成指定盘符下的文件,则可以修改代码:
File fDir=new File(File.separator);//分隔符 separator 为:
File fDir=new File(“d://”);//分隔符 separator
vinahost怎么样?vinahost是一家越南的主机商家,至今已经成13年了,企业运营,老牌商家,销售VPS、虚拟主机、域名、邮箱、独立服务器等,机房全部在越南,有Viettle和VNPT两个机房,其中VNPT机房中三网直连国内的机房,他家的产品优势就是100Mbps不限流量。目前,VinaHost商家发布了新的优惠,购买虚拟主机、邮箱、云服务器、VPS超过三个月都有赠送相应的时长,最高送半年...
LOCVPS(全球云)发布了新上韩国机房KVM架构主机信息,提供流量和带宽方式,适用全场8折优惠码,优惠码最低2G内存套餐月付仅44元起。这是一家成立较早的国人VPS服务商,目前提供洛杉矶MC、洛杉矶C3、和香港邦联、香港沙田电信、香港大埔、日本东京、日本大阪、新加坡、德国和荷兰等机房VPS主机,基于KVM或者XEN架构。下面分别列出几款韩国机房KVM主机配置信息。韩国KVM流量型套餐:KR-Pl...
gigsgigsCloud日本东京软银VPS的大带宽配置有100Mbps、150Mbps和200Mbps三种,三网都走软银直连,售价最低9.8美元/月、年付98美元。gigsgigscloud带宽较大延迟低,联通用户的好选择!Gigsgigscloud 日本软银(BBTEC, SoftBank)线路,在速度/延迟/价格方面,是目前联通用户海外VPS的最佳选择,与美国VPS想比,日本软银VPS延迟更...