标签: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),然后显示两点之间的距离。
标签:style blog color java io ar div log
原文地址:http://www.cnblogs.com/Amoxicil/p/3895409.html