问一个java编程问题:定义一个矩形类(Rectangle)
public class Rectangle { \/\/ top, left 左上角那个顶点的坐标 \/\/ width: 宽 \/\/ heigth: 长 private double top, left, width, height;\/\/ 构造函数 public Rectangle(double top, double left, double width, double height) { this.top = top;this.left = left;this.width = width;this....
急求java编码 求矩形周长 面积 以及对角线长度
求矩形周长 面积 以及对角线长度 author johnston678 version 2011-1-17 \/ public class RectangleDemo { \/\/定义长,宽 private static double x=5.9823,y=6.7323;\/\/定义周长lengthOfGirth,面积area,对角线长度lengthOfDiagonal private static double lengthOfGirth,area,lengthOfDiagonal;public static...
Java编写一个矩形类,并计算面积和周长?
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编写程序创建一个矩形类Rectangle
Rectangle(double W,double H){ width=W;height=H;} public double computePerimeter(){\/\/计算周长 return 2*(width+height);} public double computerArea(){\/\/计算面积 return height*width;} System.out.println("r1的周长"+r1.computePerimeter());System.out.println("r1的面积"+r1.compute...
定义一个矩形类,数据成员为对角线两点的坐标:X1,X2,y1,y2.均为整形...
Rectangle.h pragma once include <math.h> class CRectangle { private:int x1,x2,y1,y2;int a,b;\/\/长宽 public:CRectangle(void);CRectangle(int x1,int y1,int x2,int y2);~CRectangle(void);int calLength();\/\/计算周长 int calArea();};Rectangle.cpp include <stdio.h> include...
...矩形周长和面积的方法,并测试方法的正确性,用JAVA编写
return周长 \/ public double girth(){ return 2*(length+width);} public static void main(String[] args) { \/\/定义矩形,长为4.5,宽为3 Rectangle rectangle=new Rectangle(4.5,3);System.out.println("矩形面积是:"+rectangle.area());System.out.println("矩形周长是:"+rectangle.girth(...
定义一个矩形类Rectangle,数据成员(矩形长,宽),成员函数(给长宽赋值...
class Rectangle {private:float length,width;public:void setRectangle(float &m,float &n){length=m; width=n; };float girth(){return 2*(length+width);};float area(){return length*width;};};void main(){ float m=20;\/\/也可以为别的数 float n=30;\/\/也可以为别的数 Rectang...
用java建一个矩形类 属性:周长、面积、填充颜色、边框颜色、坐标
class Rectangle{ double width;double height;Rectangle(double W,double H){ width=W;height=H;} public double computePerimeter(){\/\/计算周长 return 2*(width+height);} public double computerArea(){\/\/计算面积 return height*width;} System.out.println("r1的周长"+r1.computePerimeter())...
Java定义一个Rectangle类
width = width;}public double getHeight() {return height;}public void setHeight(double height) {this.height = height;}}public class Test {public static void main(String[] args) {Rectangle rect = new Rectangle(4, 5);System.out.println("周长=" + rect.getC() + "\\n面积=" ...
java编程:定义一个矩形类Rectangle
public class Rectangle{ private int width;private int height;public Rectangle(){ this.width = 10;this.height = 10;} public Rectangle(int width, int height){ this.width = width;this.height = height;} public int area(){ return width * height;} \/\/省略getter\/setter } ...