当前位置:首页 » 编程语言 » javarect

javarect

发布时间: 2022-06-24 10:23:19

java Rect.java输出问题

使用Java,double 进行运算时,经常出现精度丢失的问题,总是在一个正确的结果左右偏0.0000**1。 特别在实际项目中,通过一个公式校验该值是否大于0,如果大于0我们会做一件事情,小于0我们又处理其他事情。 这样的情况通过double计算出来的结果去和0比较大小,尤其是有小数点的时候,经常会因为精度丢失而导致程序处理流程出错。
这里有篇文章,你可以去看看怎么处理
http://zhaow-381002134.javaeye.com/blog/420369

② 用JAVA编写程序,编写一个Rect类 ,要求,(1)Rect类的私有成员变量有:a:double型,代表长 b: doubl

class Rect{
private double a ;
private double b;

Rect(){
this.a = 0;
this.b = 0;
}
Rect(double len,double width){
this.a = len;
this.b = width;
}

public Double area(){
return this.a* this.b;
}
public void display(){
System.out.println(this.area());
}
}
public class userect {

public static void main(String[] args){
Rect rect1 = new Rect();
rect1.display();

Rect rect2 = new Rect(10,10);
rect2.display();
}

}

③ java 编写一个矩形类 rect 要求如下:


publicclassRect{
privateintlength;
privateintwidth;
privateintstartX;
privateintstartY

publicRect(){}

publicRect(intlength,intwidth){
this.length=length;
this.width=width;
}

publicRect(intlength,intwidth,intstartX,intstartY){
this.length=length;
this.width=width;
this.startX=startX;
this.startY=startY;
}

//不知道你要什么成员方法,我随便点....


publicvoidlouzhuhao(){
System.out.println("楼主好....");
}
publicintgetLength(){
returnlength;
}
publicvoidsetLength(intlength){
this.length=length;
}
publicintgetWidth(){
returnwidth;
}
publicvoidsetWidth(intwidth){
this.width=width;
}
publicintgetStartX(){
returnstartX;
}
publicvoidsetStartX(intstartX){
this.startX=startX;
}
publicintgetStartY(){
returnstartY;
}
publicvoidsetStartY(intstartY){
this.startY=startY;
}
}

④ Java编写一个矩形类,并计算面积和周长

class Rectangle{
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 编写一个矩形类Rect

public class Rect {
private double length;//矩形的长
private double width;//矩形的宽

public Rect() {}//默认构造器

public Rect(double length,double width) {
this.length = length;
this.width = width;
}

/**
* 取得矩形的面积
* */
public double getArea(){
return this.getLength() * this.getWidth();
}

/**
* 取得矩形的周长
* */
public double getPerimeter(){
return (this.getLength() + this.getWidth()) * 2;
}

/**
* 取得矩形的面积,需传入矩形长与宽
* */
public double getArea(double length,double width){
return length * width;
}

/**
* 取得矩形的周长,需传入矩形长与宽
* */
public double getPerimeter(double length,double width){
return (length + width) * 2;
}

public double getLength() {
return length;
}

public void setLength(double length) {
this.length = length;
}

public double getWidth() {
return width;
}

public void setWidth(double width) {
this.width = width;
}
}

⑥ 用java定义一个“矩形”(Rect)类。要求如下: 可以生成具有特定长和宽

/**
*Java技术交流:451359628
*Java技术指导:201856584
*@authorGRcoder
*/
publicclassRect{

privatelongrectLong;

privatelongrectWide;

publicRect(){
super();
}

publicRect(longrectLong,longrectWide){
super();
this.rectLong=rectLong;
this.rectWide=rectWide;
}

//面积
publiclonggetArea(){
returnthis.rectLong*this.rectWide;
}

//周长
publiclonggetPerimeter(){
return(this.rectLong+this.rectWide)*2;
}

publiclonggetRectLong(){
returnrectLong;
}

publicvoidsetRectLong(longrectLong){
this.rectLong=rectLong;
}

publiclonggetRectWide(){
returnrectWide;
}

publicvoidsetRectWide(longrectWide){
this.rectWide=rectWide;
}

@Override
publicStringtoString(){
return"Rect[rectLong="+rectLong+",rectWide="+rectWide+"]";
}

}

⑦ 用java创建一个矩形类Rectangle,其属性为各点的坐标。

class Point{
protected:
double x;
double y;
public:
Point(double a,double b){x=a;y=b;}
Point(){x=0.0;y=0.0;}
double GetX(){return x;}
double GetY(){return y;}
};
class Rect{
protected:
Point p1;
Point p2;//p1是左下角,p2是右上角
public:
Rect(double i,double j,double,k,double l):p1(i,j),p2(k,l){}
double Area()
{return ((p2.GetX()-p1.GetX())*(p1.GetY()-p2.GetY()));}
};
//用于测试的主函数
void main()
{
Rect rect1(2,3,4,5);
cout<<rect1.Area()<<endl;
}

⑧ java调用GetWindowRect怎么传参数

GetWindowRect方法的完整描述


booleancom.sun.jna.platform.win32.User32.GetWindowRect(HWNDarg0,RECTarg1)

Note:couldbefound.

传入的参数是HWND 窗口的句柄 ,根据你自己的需求传入窗口句柄

User32INSTANCE=(User32)Native.loadLibrary(User32.class,W32APIOptions.UNICODE_OPTIONS);
HWNDhwnd=User32.INSTANCE.FindWindow("yourWindowClassName","yourWindowName");//参数是:窗口的类,和窗口的标题
//这两个参数,至少一个不为null

// RECT 参数,可以提前构造一个 ,代码如下

WinDef.RECTrect=newWinDef.RECT();

最后调用GetWindowRect方法

User32.INSTANCE.GetWindowRect(hwnd,rect);//最后获取到的数据都存在了rect里面,可以取出来用
intmyWidth=rect.right-rect.left;//右顶点-左顶点=宽
intmyHight=rect.bottom-rect.top;//下顶点-上顶点=高
热点内容
诺基亚密码忘了打什么电话 发布:2024-09-17 03:27:09 浏览:555
树深度优先算法 发布:2024-09-17 03:26:58 浏览:472
跳转页源码 发布:2024-09-17 03:13:05 浏览:543
html文件上传表单 发布:2024-09-17 03:08:02 浏览:784
聊天软件编程 发布:2024-09-17 03:00:07 浏览:726
linuxoracle安装路径 发布:2024-09-17 01:57:29 浏览:688
两个安卓手机照片怎么同步 发布:2024-09-17 01:51:53 浏览:207
cf编译后没有黑框跳出来 发布:2024-09-17 01:46:54 浏览:249
安卓怎么禁用应用读取列表 发布:2024-09-17 01:46:45 浏览:524
win10设密码在哪里 发布:2024-09-17 01:33:32 浏览:662