Enter the coordinates of two points from the keyboard to calculate the distance between the two points

The code is as follows:

import java. util. Scanner; Class demo5 {public static void main (string [] args) {scanner SC = new scanner (system. In); system. Out. Println ("please enter the coordinates of the first point"); int X1 = sc.nextint(); int Y1 = sc.nextint(); system. Out. Println ("please enter the coordinates of the second point"); int x2 = sc.nextint(); int y2 = sc.nextint(); / / calculate the distance between two points int temp = (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) ; double distance=Math. pow(temp,0.5); System. out. Println ("the distance between these two points is:" + distance);}}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>