首页 > 代码库 > 两点之间的距离
两点之间的距离
import javax.swing.JOptionPane;public class Distance { public static void main(String[] args){ String input = JOptionPane.showInputDialog(null,"请输入x1的坐标:","对话框",JOptionPane.QUESTION_MESSAGE); String input1 = JOptionPane.showInputDialog(null,"请输入y1的坐标:","对话框",JOptionPane.QUESTION_MESSAGE); String input2 = JOptionPane.showInputDialog(null,"请输入x2的坐标:","对话框",JOptionPane.QUESTION_MESSAGE); String input3 = JOptionPane.showInputDialog(null,"请输入y2的坐标:","对话框",JOptionPane.QUESTION_MESSAGE); double x1 = Double.parseDouble(input); double y1 = Double.parseDouble(input1); double x2 = Double.parseDouble(input2); double y2 = Double.parseDouble(input3); System.out.println("x1 and y1:" + x1 + y1); System.out.println("x2 and y2:" + x2 + y2); System.out.println("The distance of the two points is " + Math.pow((Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), 0.5)); }}
提示输入两个点(x1,y1),(x2,y2),然后显示两点之间的距离。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。