Home  >  Article  >  Java  >  What does point mean in java

What does point mean in java

silencement
silencementOriginal
2019-05-29 14:25:0015958browse

What does point mean in java

Java problem defines a Point class

Define a Point class, the member variables are x, y, and the member function set() is set The value of x, y, get() gets the value of x, y, and defines a point object to call set() and get(), and defines a point object to call set() and get() constructor overload, distance( ) represents the distance between 2 points.

Example

public class Point {
 
    private int x;
    private int y;
 
    public Point(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 double distance(Point p1,Point p2){
        return Math.sqrt((p2.getX()-p2.getX())*(p2.getX()-p2.getX())+(p2.getY()-p1.getY())*(p2.getY()-p1.getY()));
    }
     
    public static void main(String args[]){
        Point p1 = new Point(14,17);
        Point p2 = new Point(23,90);
        double s = p1.distance(p1,p2);
        System.out.println("2点之间的距离为:"+s);
    }
}

The above is the detailed content of What does point mean in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn