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

What does point mean in java

silencement
Release: 2019-05-29 14:25:00
Original
15991 people have browsed it

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);
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template