日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

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

發布時間:2024/9/30 java 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java定义矩形类rect_Java定义矩形类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

public?class?Rectangle?{

float?width,height;

/**

*?計算面積

*?@return?矩形的面積

*/

public?float?getArea(){

return?width*height;

}

/**

*?計算周長

*?@return?矩形的周長

*/

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的周長:"+r1.getCircumference());

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

}

}

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。