Kamis, 19 Agustus 2010

Mencari Jarak 2 Benda

import java.util.Scanner;

public class jarak{

public static void main (String[] args){

Scanner s = new Scanner(System.in);

System.out.println("nilai x1 =");
int x1=s.nextInt();
System.out.println("nilai x2 =");
int x2=s.nextInt();
System.out.println("nilai y1 =");
int y1=s.nextInt();
System.out.println("nilai y2 =");
int y2=s.nextInt();

int dx= (int)(x2-x1);
int dy= (int)(y2-y1);
Math.abs (dx);
Math.abs (dy);
double hasil=Math.sqrt(dx*dx)+(dy*dy);

System.out.println("Jadi jarak antar pesawat adalah =" +hasil);

}

}

Tidak ada komentar:

Posting Komentar