码迷,mamicode.com
首页 > 其他好文 > 详细

HW3.28

时间:2016-08-13 14:05:18      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8 
 9         System.out.print("Enter r1‘s center x-, y-coordinates, width, and height: ");
10         double x1 = input.nextDouble();
11         double y1 = input.nextDouble();
12         double width1 = input.nextDouble();
13         double height1 = input.nextDouble();
14 
15         System.out.print("Enter r2‘s center x-, y-coordinates, width, and height: ");
16         double x2 = input.nextDouble();
17         double y2 = input.nextDouble();
18         double width2 = input.nextDouble();
19         double height2 = input.nextDouble();
20 
21         input.close();
22 
23         boolean isInside = false;
24 
25         if((x1 - width1 / 2 >= x2 - width2 / 2) && (x1 + width1 / 2 <= x2 + width2 / 2) && 
26             (y1 - height1 / 2 >= y2 - height2 / 2) && (y1 + height1 / 2 <= y2 + height2 / 2))
27         {
28             System.out.println("r1 is inside r2");
29             isInside = true;
30         }
31         else if((x2 - width2 / 2 >= x1 - width1 / 2) && (x2 + width2 / 2 <= x1 + width1 / 2) && 
32             (y2 - height2 / 2 >= y1 - height1 / 2) && (y2 + height2 / 2 <= y1 + height1 / 2))
33         {
34             System.out.println("r2 is inside r1");
35             isInside = true;
36         }
37             
38 
39         if(!isInside)
40         {
41             if(x1 >= x2)
42             {
43                 if(y1 >= y2)
44                 {
45                     if((x1 - width1 / 2 >= x2 + width2 / 2) && (y1 - width1 / 2 >= y2 + width2 / 2))
46                         System.out.println("r2 does not overlap r1");
47                     else
48                         System.out.println("r2 overlaps r1");
49                 }
50                 else
51                 {
52                     if((x1 - width1 / 2 >= x2 + width2 / 2) && (y1 + width1 / 2 <= y2 - width2 / 2))
53                         System.out.println("r2 does not overlap r1");
54                     else
55                         System.out.println("r2 overlaps r1");
56                 }
57             }
58             else
59             {
60                 if(y1 >= y2)
61                 {
62                     if((x1 + width1 / 2 <= x2 - width2 / 2) && (y1 - width1 / 2 >= y2 + width2 / 2))
63                         System.out.println("r2 does not overlap r1");
64                     else
65                         System.out.println("r2 overlaps r1");
66                 }
67                 else
68                 {
69                     if((x1 + width1 / 2 <= x2 - width2 / 2) && (y1 + width1 / 2 <= y2 - width2 / 2))
70                         System.out.println("r2 does not overlap r1");
71                     else
72                         System.out.println("r2 overlaps r1");
73                 }
74             }
75         }
76     }
77 }

 

HW3.28

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5767782.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!