/**
*
*/
package com.gem.demo.day05_practice;
import java.util.Scanner;
/**
*
* Description:定义类Point,类中有方法用来求该点到原点的距离
*
* @author HadwinLing
*
* @date 2020年1月14日下午5:56:48
*
* @version 0.0.1
*
*/
public class PointTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
point point1 = new point(1,1);
point point2 = new point(4,5);
System.out.println("point1与point2的长度为 "+getLength(point1,point2));
}
public static double getLength(point point1,point point2) {
double lenX = point1.pointX-point2.pointX;
double lenY = point1.pointY-point2.pointY;
double len = Math.sqrt(lenX*lenX+lenY*lenY);
return len;
}
}
class point{
int pointX;
int pointY;
point(){
pointX= 0;
pointY=0;
}
point(int pointX,int pointY){
this.pointX = pointX;
this.pointY = pointY;
}
}
java中定义类Point,类中有方法用来求该点到原点的距离
猜你喜欢
转载自blog.csdn.net/Alingyuzi/article/details/103980228
今日推荐
周排行