Java矩形代码_[蓝桥杯][基础练习VIP]矩形面积交 (Java代码)

解题思路:

画图形 找规律

注意事项:

参考代码:

import java.util.Scanner;

public class Main

{

/*

* 平面上有两个矩形,它们的边平行于直角坐标系的X轴或Y轴。对于每个矩形, 我们给出它的一对相对顶点的坐标,请你编程算出两个矩形的交的面积。

*/

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

double[][] arr = new double[2][4];

for (int i = 0; i < 2; i++)

{

for (int j = 0; j < 4; j++)

{

arr[i][j] = input.nextDouble();

}

}

double x1 = min(max(arr[0][0], arr[0][2]), max(arr[1][0], arr[1][2]));

double x2 = max(min(arr[0][0], arr[0][2]), min(arr[1][0], arr[1][2]));

double y1 = min(max(arr[0][1], arr[0][3]), max(arr[1][1], arr[1][3]));

double y2 = max(min(arr[0][1], arr[0][3]), min(arr[1][1], arr[1][3]));

double width = x1 - x2;

double length = y1 - y2;

double s = width * length;

if (width > 0 && length > 0)

{

System.out.printf("%.2f", s);

} else

{

System.out.println("0.00");

}

}

public static double max(double a, double b)

{

return ((a > b) ? a : b);

}

public static double min(double a, double b)

{

return ((a < b) ? a : b);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C++语言画矩形 "_AFXDLL" "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\Test.rc"" Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8A.tmp" with contents [ /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Fp"Debug/Test.pch" /Yu"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\MainFrm.cpp" "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\Picdlg.cpp" "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\Test.cpp" "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\TestDoc.cpp" "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\TestView.cpp" ] Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8A.tmp" Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8B.tmp" with contents [ /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Fp"Debug/Test.pch" /Yc"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\StdAfx.cpp" ] Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8B.tmp" Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8C.tmp" with contents [ /nologo /subsystem:windows /incremental:yes /pdb:"Debug/Test.pdb" /debug /machine:I386 /out:"Debug/Test.exe" /pdbtype:sept ".\Debug\MainFrm.obj" ".\Debug\Picdlg.obj" ".\Debug\StdAfx.obj" ".\Debug\Test.obj" ".\Debug\TestDoc.obj" ".\Debug\TestView.obj" ".\Debug\Test.res" ] Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8C.tmp" <h3>Output Window</h3> Compiling resources... Compiling... StdAfx.cpp Compiling... MainFrm.cpp Picdlg.cpp Test.cpp TestDoc.cpp TestView.cpp Generating Code... Linking...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值