Java中当前对象引用

题:

计算机画图时,有点的概念,每个点由它的横坐标x 和 纵坐标 y 描述。

写一个类。

求两个点之间的曼哈顿距离 = 横向距离 + 纵向距离

例如,一个点(0,0) 和另一个点(1,1)的曼哈顿距离为2

1package test; 2 3public class Point 4{ 5 6 public Point() 7 { 8 // TODO Auto-generated constructor stub 9 } 10 11 public int x; 12 public int y; 13 14 public int manhattan(Point n) 15 { 16 int dx = Math.abs(n.x - this.x); 17 int dy = Math.abs(n.y - this.y); 18 return dx + dy; 19 } 20} 21 22 23 24package test; 25 26public class test 27{ 28 29 public test() 30 { 31 // TODO Auto-generated constructor stub 32 } 33 34 public static void main(String[] args) 35 { 36 // TODO Auto-generated method stub 37 Point p1 = new Point(); 38 p1.x = 4; 39 p1.y = 5; 40 Point p2 = new Point(); 41 p2.x = 3; 42 p2.y = 5; 43 int d = p1.manhattan(p2); 44 System.out.println(d); 45 46 } 47 48}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

java 复制Map对象(深拷贝与浅拷贝)

java复制Map对象(深拷贝与浅拷贝)CreationTime2018年6月4日10点00分Author:Marydon1.深拷贝与浅拷贝  浅拷贝:只复制对象的引用,两个引用仍然指向同一个对象

CGAL HelloWorld

点和线段如何创建点和线段,并计算两点之间的距离、点到线段的距离、点与线段的位置关系和中点。定义Kernel(几何图元)操作predicate(位置,距离和中点)Codeinclude<iostreaminclude<CGAL/Simple_cartesian.hty