Exercise02_15
1 import javax.swing.JOptionPane; 2 public class Distance { 3 public static void main(String[] args){ 4 String number; 5 double x1,x2,y1,y2,distance; 6 number=JOptionPane.showInputDialog(null,"输入x1"); 7 x1=Double.parseDouble(number); 8 number=JOptionPane.showInputDialog(null,"输入x2"); 9 x2=Double.parseDouble(number); 10 number=JOptionPane.showInputDialog(null,"输入y1"); 11 y1=Double.parseDouble(number); 12 number=JOptionPane.showInputDialog(null,"输入y2"); 13 y2=Double.parseDouble(number); 14 distance=Math.pow((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1), 0.5); 15 int messageType=JOptionPane.INFORMATION_MESSAGE; 16 String message="The distance between the two points is " + distance; 17 JOptionPane.showMessageDialog(null,message,"result",messageType); 18 19 } 20 }