DistanceCalculation

DistanceCalculation - double distance; Scanner sc = new...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // DistanceCalculation.java Author: Lewis and Loftus // // Solution to Programming Project 2.8 //******************************************************************** / import java.util.Scanner; i public class DistanceCalculation { //----------------------------------------------------------------- // Computes the distance between two points using the distance // formula. //----------------------------------------------------------------- public static void main (String[] args) { int x1, y1, x2, y2;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: double distance; Scanner sc = new Scanner(System.in); System.out.println ("Enter the first coordinate values:"); x1 = Integer.parseInt(sc.nextLine()); y1 = Integer.parseInt(sc.nextLine()); System.out.println ("Enter the second coordinate values:"); x2 = Integer.parseInt(sc.nextLine()); y2 = Integer.parseInt(sc.nextLine()); distance = Math.sqrt( Math.pow(x2-x1,2) + Math.pow(y2-y1,2) ); System.out.println ("The distance between (" + x1 + "," + y1 + ") and (" + x2 + "," + y2 + ") is " + distance); } }...
View Full Document

Ask a homework question - tutors are online