日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

java定义矩形类rect_Java定义矩形类

發(fā)布時(shí)間:2024/9/30 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java定义矩形类rect_Java定义矩形类 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

矩形類package?cn.edu.uibe.oop;

public?class?Rectangle?{

float?width,height;

/**

*?計(jì)算面積

*?@return?矩形的面積

*/

public?float?getArea(){

return?width*height;

}

/**

*?計(jì)算周長(zhǎng)

*?@return?矩形的周長(zhǎng)

*/

public?float?getCircumference(){

return?2*(width+height);

}

/**

*?改變矩形的大小

*?@param?w?寬度

*?@param?h?高度

*/

public?void?resize(float?w,float?h){

width?=?w;

height?=?h;

}

/**

*?輸出矩形的寬和高

*/

public?void?printSize(){

System.out.println("寬:"+width+"?高:"+height);

}

public?static?void?main(String[]?args)?{

Rectangle?r1?=?new?Rectangle();

Rectangle?r2?=?new?Rectangle();

r1.resize(4.0F,?3.0F);

r2.resize(2,?5);

r1.printSize();

r2.printSize();

System.out.println("矩形1的面積:"+r1.getArea());

System.out.println("矩形2的面積:"+r2.getArea());

System.out.println("矩形1的周長(zhǎng):"+r1.getCircumference());

System.out.println("矩形2的周長(zhǎng):"+r2.getCircumference());

}

}

總結(jié)

以上是生活随笔為你收集整理的java定义矩形类rect_Java定义矩形类的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。