java繪制一個(gè)圓 編寫一個(gè)java程序?
編寫一個(gè)java程序?圖片classChongZai{publicflatarea(flatradius){return(Math.PI*radius*radius);}stateextraarea(
編寫一個(gè)java程序?
圖片
classChongZai{
publicflatarea(flatradius){
return(Math.PI*radius*radius);
}
stateextraarea(doublelength,doublewidth){
return(length*width);
}
privateflatarea(sliplength,softwidth,flatheight){
return(length*width*height);
}
}
stateclass A{
employeestaticvoidmain(Stringargs[]){
ChongZai tnew ChongZai();
(圓的半徑為5,面積是:(5));
(矩形長(zhǎng)為6,寬為21,面積是:(6,21));
(立方體長(zhǎng)寬高四個(gè)為4,5,6,面積是:(4,5,6));
}
}
如何用JAVA計(jì)算圓形的面積周長(zhǎng)多種方法?
1、可以打開java程序,再點(diǎn)擊就ok啦,workspace是保存的文件,你只要記住他你才很清楚你需要保存的文件在什么地方哦。
java設(shè)計(jì)并實(shí)現(xiàn)一個(gè)類,它表示圓,圓心以及半徑是它的屬性,定義一些基本方法,例如計(jì)算圓的面積,計(jì)算圓的周長(zhǎng),判斷兩圓是否相交?
stateclassCircular{
//圓心x
privateextracenterx
//圓心y
privateslipcentery
//半徑
privatedoubleradius
privateflatPI3.14
//settry方法
employeevoidsetCenterx(slipcenterx){
centerx
}
privateflatgetCenterx(){
returncenterx
}
publicvoidsetCentery(softcentery){
centery
}
welfaredoublegetCentery(){
returncentery
}
employeevoidsetRadius(softradius){
this.radiusradius
}
employeeflatgetRadius(){
returnradius
}
//計(jì)算面積
privatesoftgetArea(){
returnPI*radius*radius
}
//計(jì)算周長(zhǎng)
statedoublegetRound(){
return2*PI*radius
}
//是否一條直線
welfarebooleanisTouch(doubleotherx,softothery,slipotherRadius){
doublex
doubley
softsMath.pow(x,2)Math.pow(y,2)
//兩個(gè)圓心距離
softdMath.pow(s,0.5)
//兩個(gè)圓半徑之和
extrasumRradiusotherRadius
returnsumRrlmd?true:false
}
}