public class J3_28 {
public static void main(String[] args) {
// TODO Auto-generated method stub
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter r1's center x-,y-cooordinates, width,and height:");
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double w1 = input.nextDouble();
double h1 = input.nextDouble();
System.out.print("Enter r2's center x-,y-coordinates, width,and height:");
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double w2 = input.nextDouble();
double h2 =input.nextDouble();
double xDistance = x1 -x2 >=0 ? x1-x2 : x2-x1;
double yDistance = y1-y2 >=0? y1-y2 : y2-y1;
if (xDistance <= (w1 - w2) / 2 && yDistance <= (h1 - h2) / 2)
System.out.println("r2 is inside r1");
else if (xDistance <= (w1 + w2) / 2 && yDistance <= (h1 + h2) / 2)
System.out.println("r2 overlaps r1");
else System.out.println("r2 does not overlap r1");
}
}
Java语言程序设计(基础篇)第十版 综合题 **3.28(几何:两个矩形)
最新推荐文章于 2022-01-20 07:52:46 发布