import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);

         System.out.print("Enter r1's center x-, y-coordinates, width, and height: ");
         double x1 = input.nextDouble();
         double y1 = input.nextDouble();
         double width1 = input.nextDouble();
         double height1 = input.nextDouble();

         System.out.print("Enter r2's center x-, y-coordinates, width, and height: ");
         double x2 = input.nextDouble();
         double y2 = input.nextDouble();
         double width2 = input.nextDouble();
         double height2 = input.nextDouble();

         input.close();

         boolean isInside = false;

         if((x1 - width1 / 2 >= x2 - width2 / 2) && (x1 + width1 / 2 <= x2 + width2 / 2) &&
             (y1 - height1 / 2 >= y2 - height2 / 2) && (y1 + height1 / 2 <= y2 + height2 / 2))
         {
             System.out.println("r1 is inside r2");
             isInside = true;
         }
         else if((x2 - width2 / 2 >= x1 - width1 / 2) && (x2 + width2 / 2 <= x1 + width1 / 2) &&
             (y2 - height2 / 2 >= y1 - height1 / 2) && (y2 + height2 / 2 <= y1 + height1 / 2))
         {
             System.out.println("r2 is inside r1");
             isInside = true;
         }

         if(!isInside)
         {
             if(x1 >= x2)
             {
                 if(y1 >= y2)
                 {
                     if((x1 - width1 / 2 >= x2 + width2 / 2) && (y1 - width1 / 2 >= y2 + width2 / 2))
                         System.out.println("r2 does not overlap r1");
                     else
                         System.out.println("r2 overlaps r1");
                 }
                 else
                 {
                     if((x1 - width1 / 2 >= x2 + width2 / 2) && (y1 + width1 / 2 <= y2 - width2 / 2))
                         System.out.println("r2 does not overlap r1");
                     else
                         System.out.println("r2 overlaps r1");
                 }
             }
             else
             {
                 if(y1 >= y2)
                 {
                     if((x1 + width1 / 2 <= x2 - width2 / 2) && (y1 - width1 / 2 >= y2 + width2 / 2))
                         System.out.println("r2 does not overlap r1");
                     else
                         System.out.println("r2 overlaps r1");
                 }
                 else
                 {
                     if((x1 + width1 / 2 <= x2 - width2 / 2) && (y1 + width1 / 2 <= y2 - width2 / 2))
                         System.out.println("r2 does not overlap r1");
                     else
                         System.out.println("r2 overlaps r1");
                 }
             }
         }
     }
 }

HW3.28的更多相关文章

  1. 28个你必须知道的HTML5的新特性,技巧以及技术

    崭新新的页面布局 传统的: HTML5: 1. 新的Doctype 尽管使用<!DOCTYPE html>,即使浏览器不懂这句话也会按照标准模式去渲染 2. Figure元素 用<f ...

  2. CSharpGL(28)得到高精度可定制字形贴图的极简方法

    CSharpGL(28)得到高精度可定制字形贴图的极简方法 回顾 以前我用SharpFont实现了解析TTF文件从而获取字形贴图的功能,并最终实现了用OpenGL渲染文字. 使用SharpFont,美 ...

  3. 来,一起让我们越来越懒,面向CSS、JS未来编程。(9.28已更新)

    2016.10.29更新 本文存在大量的错误,仅供参考. 不知不觉在前端领域马上一个年头就要过去了,然而再看看自己的代码,果然够烂,那么为什么代码一直没有用面向对象的思维去写CSS呢?首先有两点:一点 ...

  4. MySQL报错:Got error 28 from storage engine

    今天碰到数据库出错: Got error 28 from storage engine 查了一下,数据库文件所在的盘应该没事,应该是数据库用的临时目录空间不够 问题原因: 磁盘临时空间不够导致. 解决 ...

  5. [.net 面向对象程序设计进阶] (28) 结束语——告别2015

    [.net 面向对象程序设计进阶] (28) 结束语——告别2015 <.net面向对象程序设计进阶>这一系列文章写了太长的时间了,大概有半年没写,在年底又一口气写了好几篇.在整个过程中目 ...

  6. 背水一战 Windows 10 (28) - 控件(文本类): TextBox, PasswordBox

    [源码下载] 背水一战 Windows 10 (28) - 控件(文本类): TextBox, PasswordBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) T ...

  7. 10月28日PHP基础知识测试题

    本试题共40道选择题,10道判断题,考试时间1个半小时 一:选择题(单项选择,每题2分): 1. LAMP具体结构不包含下面哪种(A) A:Windows系统 B:Apache服务器 C:MySQL数 ...

  8. CentOS6.3编译安装Nginx1.4.7 + MySQL5.5.25a + PHP5.3.28

    [准备工作] #在编译安装lnmp之前,首先先卸载已存在的rpm包. rpm -e httpd rpm -e mysql rpm -e php yum -y remove httpd yum -y r ...

  9. 记 Mac Pro 系统升级后,编译安装 PHP-5.6.28 / PHP-7.0 报错修复过程

    买 Mac Pro 的时候,系统为 OS X 10.11.5,编译 PHP-5.6.21 的时候,也遇到一些坑,安装过程记录如下: Mac Pro 编译安装 PHP 5.6.21 及 问题汇总 后来, ...

随机推荐

  1. 使用grub硬盘重装ubuntu

    电脑一直是双系统,Windows8 + Ubuntu13.04,昨天瞎搞,更新了一下QT,结果就不能开机了...真心难. 老系统坏了也好,正好可以装个Ubuntu14.04LTS.手边没有U盘,可以把 ...

  2. 属性观察者willSet与didSet

    在Swift中使用willSet和didSet这两个特性来监视属性的除初始化之外的属性值变化. willSet里面是新值,即属性即将要变为的值:didSet里面是旧值,即属性变化之前的值. impor ...

  3. appcache checking update

    <!DOCTYPE html> <html manifest="a.appcache"> <head> <title></ti ...

  4. final, finally 和finalize的区别

    final 修饰符(关键字) 如果一个类被声明为final,意味着它不能再派生新的子类,不能作为父类被继承.因此一个类不能及被声明为abstract,又被声明为final的.将变量或方法声明为fina ...

  5. delphi xe5 android 使用样式(风格)

    1.在界面上添加 TStyleBook 控件 2.点击Resource 选择xe5程序安装带的几个风格的其中之一,路径存放在: C:\Program Files\Embarcadero\RAD Stu ...

  6. jQuery CSS 添加/删除类名

    addClass(class) — 为每个匹配的元素添加指定的类名.参数 : class — 一个或多个要添加到元素中的CSS类名,请用空格分开(String)示例 一 :为匹配的元素加上 'sele ...

  7. Windows 2008 故障转移群集介绍

    转载:http://dufei.blog.51cto.com/382644/902026 今天有客户问起Windows 群集的相关内容,毕竟Windows Server2008所支持的群集技术和Win ...

  8. XSS脚本攻击漫谈

    XSS跨站脚本攻击一直都被认为是客户端  Web安全中最主流的攻击方式.因为  Web环境的复杂性以及 XSS跨站脚本攻击的多变性,使得该类型攻击很难彻底解决.那么,XSS跨站脚本攻击具体攻击行为是什 ...

  9. Codeforces Round #210

    A:简单题: #include<cstdio> using namespace std; int n,k; int main() { scanf("%d%d",& ...

  10. PHP7正式版测试,性能惊艳!

    本周迎来2015年编程语言界的两件大事,Swift7 开源, PHP7 发布.这两件大事,都是可以载入相应的编程语言的史册级的事件. Swift 开源的事,咱先不说了,知乎上也有热烈的讨论,我们今天就 ...