課後習題page101.pp3.4

//********************************************
//  distanceOfTwoPoint.java  Author: Jayson
//*******************************************

import java.util.Scanner;

public class distanceOfTwoPoint 
{
	//-----------------------------------------
	//  input two point's coordinate.
	//  then calculate their distace
	//----------------------------------------
	public static void main(String[] args)
	{
		double x1, y1, x2, y2, distance;
		Scanner scan = new Scanner(System.in);
		
		System.out.println("Please input two point's coordinate");
		
		x1 = scan.nextDouble();
		y1 = scan.nextDouble();
		x2 = scan.nextDouble();
		y2 = scan.nextDouble();
		
		scan.close();
		
		distance = Math.sqrt(Math.pow(x2-x1, 2)+Math.pow(y2-y1, 2));
		
		System.out.println("Their distance is: " + distance);
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章