zoukankan      html  css  js  c++  java
  • 设计一个Mypoint类,求两个点之间的距离

    package Test;
    
    public class test6 {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Mypoint mypoint1 = new Mypoint(1,1);
            Mypoint mypoint2 = new Mypoint(2,2);
            double distance = Mypoint.getDistance(mypoint1, mypoint2);
            System.out.println("这两个点的距离是:"+distance);
        }
    
    }
    class Mypoint {
        
        private int x = 0;
        private int y = 0;
        Mypoint(){
            x = 0;
            y = 0;
        }
        Mypoint(int x,int y){
            this.x = x;
            this.y = y;
        }
        public int getX() {
            return x;
        }
        public void setX(int x) {
            this.x = x;
        }
        public int getY() {
            return y;
        }
        public void setY(int y) {
            this.y = y;
        }
        public static double getDistance(Mypoint mypoint1,Mypoint mypoint2) {
            
            double distance = Math.sqrt(Math.pow((mypoint1.getX()-mypoint2.getX()), 2)+Math.pow((mypoint1.getY()-mypoint2.getY()), 2));
            return distance;
        }
    }
  • 相关阅读:
    Alpha项目冲刺_博客链接合集
    项目系统设计
    项目需求分析
    项目选题
    项目展示
    原型设计 + 用户规格说明书
    测试与优化
    结对作业1
    MathExam6317
    js入门基础
  • 原文地址:https://www.cnblogs.com/xiexiaofei/p/11541639.html
Copyright © 2011-2022 走看看