码迷,mamicode.com
首页 > 其他好文 > 详细

两点之间的距离

时间:2014-08-06 21:42:42      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   io   ar   div   log   

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),然后显示两点之间的距离。

两点之间的距离,布布扣,bubuko.com

两点之间的距离

标签:style   blog   color   java   io   ar   div   log   

原文地址:http://www.cnblogs.com/Amoxicil/p/3895409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!