import javax.swing.JOptionPane; import java.lang.Math; import java.text.DecimalFormat; public class Distancia{ public static void main(String[] args){ String x1 = JOptionPane.showInputDialog("Ingresa un x1:"); String y1 = JOptionPane.showInputDialog("Ingresa un y1:"); String x2 = JOptionPane.showInputDialog("Ingresa un número x2:"); String y2 = JOptionPane.showInputDialog("Ingresa un número y2:"); JOptionPane.showMessageDialog(null,CalculaDistancia(x1,y1,x2,y2), "Distancia entre dos Puntos",JOptionPane.PLAIN_MESSAGE); } public static String CalculaDistancia(String x_1, String y_1,String x_2, String y_2){ double cordX1 = Double.valueOf(x_1).doubleValue(); double cordY1 = Double.valueOf(y_1).doubleValue(); double cordX2 = Double.valueOf(x_2).doubleValue(); double cordY2 = Double.valueOf(y_2).doubleValue(); double respuesta = Math.sqrt( Math.pow ((cordX2-cordX1),2) + Math.pow((cordY2-cordY1),2)); DecimalFormat dosdecimales = new DecimalFormat("0.00"); String resultado = "La Distacia es: " + dosdecimales.format(respuesta); return resultado; } }