成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

java代碼求矩形的面積 c語言求矩形面積代碼

Java編寫一個(gè)矩形類,并計(jì)算面積和周長?

class Rectangle{

中站網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),中站網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為中站1000多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個(gè)售后服務(wù)好的中站做網(wǎng)站的公司定做!

private int width = 2;

private int length = 1;

public int getWidth(){

return this.width;

}

public void setWidth(int w){

this.width = w;

}

public int getLength(){

return this.length;

}

public void setLength(int l){

this.length = l;

}

public int getArea(){

return this.length * this.width;

}

public int getCircumference(){

return (this.length + this.width) * 2;

}

public Rectangle(){}

public Rectangle(int l, int w){

this.length = l;

this.width = w;

}

}

public class demo{

public static void main(String[] args) {

Rectangle rect = new Rectangle(30, 8);

System.out.print("長方形的面積是:");

System.out.println(rect.getArea());

System.out.printf("長方形的周長是:%d\n", rect.getCircumference());

}

}

用JAVA計(jì)算一個(gè)矩形的面積?

//計(jì)算矩形的面積

public class RectArea {

public static double getArea(double width, double higth) {

double area = 0.0;// 矩形面積

// 判斷輸入是否合理

if (!(width = 0 || higth = 0)) {

area = width * higth;

return area;// 返回面積

} else {

System.out.println("請輸入合理的長寬");

return -1;

}

}

public static void main(String[] args) {

//測試 寬:10.0 高:20.0

System.out.println("矩形面積" + RectArea.getArea(10.0, 20.0));

}

}

Java利用方法的重載計(jì)算圓形和矩形的面積

public class Test {

public static void main(String[] args) {

System.out.println("圓的面積:" + area(2));

System.out.println("三角形的面積:" + area(3,4,5));

System.out.println("矩形的面積:" + area(3,4));

}

//求圓的面積

public static double area(double radius){

return Math.PI * radius * radius;

}

//求三角形的面積

public static double area(double a, double b, double c){

double s = (a + b + c) / 2;

return Math.sqrt(s*(s-a)*(s-b)*(s-c));

}

//求矩形的面積

public static double area(double width, double height){

return width * height;

}

//求橢圓的面積

/* public static double area(double a, double b){

return Math.PI * a * b;

}*/

}

求橢圓面積需要2個(gè)參數(shù),求矩形面積也需要2個(gè)參數(shù),這些參數(shù)的數(shù)據(jù)類型、順序和數(shù)量完全一致,無法實(shí)現(xiàn)重載,除非改名。

java求矩形面積 矩形的面積怎么求

import java.util.*;

public class Rectangle {

private float length; //定義長變量

private float width; // 寬變量

public Rectangle(float length,float width){

this.length=length;

this.width=width;

}

public float getGirth(){

return (length+width)*2;

} //求周長方法

public float getArea(){

return length*width;

} //求面積方法

public static void main (String[] args) {

Scanner in=new Scanner(System.in);//調(diào)用輸入方法

System.out.println ("請輸入矩形的長:");

float a=in.nextFloat();

System.out.println ("請輸入矩形的寬:");

float b=in.nextFloat();

System.out.println ("矩形周長為:"+new Rectangle(a,b).getGirth());

System.out.println ("矩形面積為:"+new Rectangle(a,b).getArea());

}

}

計(jì)算矩形面積 用java

方法的重載

class Circle

{

private float a;

private float b;

public float area;

public void setA(float a)

{

this.a=a;

}

public float getA()

{

return this.a;

}

public void setArea(float b)

{

this.b=b;

}

public float getB()

{

return this.b;

}

public void into(float a)

{

area=a*a;

System.out.println("這是一個(gè)正方形...面積為: "+area);

}

public void into(float a,float b)

{

area=a*b;

System.out.println("這是一個(gè)正方形...面積為: "+area);

}

}

public class Java

{

public static void main(String args[])

{

Circle c=new Circle();

c.into(2);

c.into(2,3);

}

}

網(wǎng)站名稱:java代碼求矩形的面積 c語言求矩形面積代碼
標(biāo)題鏈接:http://jinyejixie.com/article12/hpcdgc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)站建設(shè)標(biāo)簽優(yōu)化、網(wǎng)站維護(hù)建站公司、App設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司
晋宁县| 甘谷县| 山东省| 盐池县| 彰化市| 麟游县| 福安市| 宁河县| 浦县| 双峰县| 通山县| 桐庐县| 揭西县| 原阳县| 庆阳市| 仪征市| 三台县| 呼和浩特市| 辉县市| 马尔康县| 绥滨县| 项城市| 兴业县| 昭觉县| 宁强县| 垣曲县| 曲沃县| 新巴尔虎右旗| 镇康县| 正蓝旗| 石柱| 宽甸| 泾川县| 革吉县| 全州县| 武宁县| 苏州市| 潞城市| 仁怀市| 通辽市| 峨眉山市|