zoukankan      html  css  js  c++  java
  • Java中当前对象引用

    题:

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

    写一个类。

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

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

    package test;
    
    public class Point
    {
    
        public Point()
        {
            // TODO Auto-generated constructor stub
        }
    
        public int x;
        public int y;
    
        public int manhattan(Point n)
        {
            int dx = Math.abs(n.x - this.x);
            int dy = Math.abs(n.y - this.y);
            return dx + dy;
        }
    }
    
    
    
    package test;
    
    public class test
    {
    
        public test()
        {
            // TODO Auto-generated constructor stub
        }
    
        public static void main(String[] args)
        {
            // TODO Auto-generated method stub
            Point p1 = new Point();
            p1.x = 4;
            p1.y = 5;
            Point p2 = new Point();
            p2.x = 3;
            p2.y = 5;
            int d = p1.manhattan(p2);
            System.out.println(d);
    
        }
    
    }
  • 相关阅读:
    Largest Submatrix of All 1’s
    Max Sum of Max-K-sub-sequence
    Sticks Problem
    Splay模版
    B. Different Rules
    链表合并 leetcode
    K个一组翻转链表
    反转链表2 leetcode
    nodejs简单仿apache页面
    HTML 5 Web Workers
  • 原文地址:https://www.cnblogs.com/jenrry/p/10026138.html
Copyright © 2011-2022 走看看