2016-04-05 16 views
-2
import java.util.Scanner; 
//distance = square root of [(x2-x1)squared + (y2-y1)squared + (z2-z1)squared] 

public class FirstCode 
{ 
    static double distance(double x1, double y1, double z1, double x2, double y2, double z2) 
    { 
     return Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1)); 
    } 

    public static void main(String[] args) 
    { 
     double x2, x1, y2, y1, z2, z1; 
     double distance; 

     Scanner scan = new Scanner (System.in); 

     System.out.println("Enter the x coordinate for point 1: "); 
     x1 = scan.nextDouble(); 

     System.out.println("Enter the y coordinate for point 1: "); 
     y1 = scan.nextDouble(); 

     System.out.println("Enter the x coordinate for point 2: "); 
     x2 = scan.nextDouble(); 

     System.out.println("Enter the y coordinate for point 2: "); 
     y2 = scan.nextDouble(); 

     System.out.println("Enter the z coordinate for point 3: "); 
     z1 = scan.nextDouble(); 

     System.out.println("Enter the z coordinate for point 3: "); 
     z2 = scan.nextDouble(); 
     distance = distance(x1,y1,x2,y2,z1,z2); 
     System.out.println("The distance between the two points is " + distance + " ."); 
    } 
} 
+0

Koordinatlar (x1, y1, z1) = (15.34, 1.15, 0.19), (x 2, y2, z2) = (-15,34, 1.15, 0.19) Yanıt 30.69 ancak 15.34 gösteren yukarıdaki Java kodu? –

+0

İlk sürümden bu yana tüm değişikliklerinizi geri aldım. Buna bir cevap vardı, bu nedenle soruyu yeni bir şeye büyük ölçüde değiştirmenize izin verilmiyor. Yeni bir sorunuz varsa yeni bir gönderi oluşturun. – Tom

cevap

1

Tarayıcıyı en sonunda kapatın.

scan.close();