Question

If x1, y1, x2, and y2 are respectively the coordinates of two points, what is the correct java code to calculate and display the distance between these two points using the Distance Formula? Distance formula d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} d = distance (x_1, y_1) = coordinates of the first point (x_2, y_2) = coordinates of the second point

          If x1, y1, x2, and y2 are respectively the coordinates of two points, what is the
correct java code to calculate and display the distance between these two points
using the Distance Formula?
Distance formula
d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}
d = distance
(x_1, y_1) = coordinates of the first point
(x_2, y_2) = coordinates of the second point
        
Show more…
If x1, y1, x2, and y2 are respectively the coordinates of two points, what is the
correct java code to calculate and display the distance between these two points
using the Distance Formula?
Distance formula
d = √((x2 - x1)^2 + (y2 - y1)^2)
d = distance
(x1, y1) = coordinates of the first point
(x2, y2) = coordinates of the second point

Added by Matthew S.

Close

Computer Science and Information Technology
Computer Science and Information Technology
Trishna Knowledge Systems 2018 Edition
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
If x1, y1, x2, and y2 are respectively the coordinates of two points, what is the correct Java code to calculate and display the distance between these two points using the Distance Formula? Distance formula d = √((x2 - x1)^(2) + (y2 - y1)^(2)) d = distance (x1, y1) = coordinates of the first point (x2, y2) = coordinates of the second point
Close icon
Play audio
Feedback
Powered by NumerAI
Kathleen Carty Ivan Kochetkov
Jennifer Stoner verified

Harriet O'Brien and 98 other subject AP CS educators are ready to help you.

Ask a new question

*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Key Concept
Premium Feature
Explore the core concept behind this problem.
Play button
Key Concept
Premium Feature
Explore the core concept behind this problem.
Your browser does not support the video tag.

*

Recommended Videos

-
geometry-distance-of-two-points-write-a-program-that-prompts-the-user-to-enter-two-points-x-1-y-1-an

(Geometry: distance of two points) Write a program that prompts the user to enter two points $(x 1, y 1)$ and $(x 2, y 2)$ and displays their distance between them. The formula for computing the distance is $\sqrt{\left(x_{2}-x_{1}\right)^{2}+\left(y_{2}-y_{1}\right)^{2}}$. Note that you can use Math.pow(a, 0.5 ) to compute $\sqrt{a}$. Here is a sample run:

Introduction to Java Programming

the-formula-for-the-distance-between-any-point-px1-y1-z1-and-any-plane-ax-by-cz-d-0-is-given-by-hax-by-cz-dl-d-va-b-c2-prove-this-formula-is-correct-by-using-a-method-similar-to-finding-the-32336

The formula for the distance between any point P(x1, y1, z1) and any plane Ax + By + Cz + D = 0 is given by: d = |Ax1 + By1 + Cz1 + D| / sqrt(A^2 + B^2 + C^2) Prove this formula is correct by using a method similar to finding the distance between a point and a line in two dimensions.

Madhur L.

write-a-python-program-to-compute-the-distance-between-the-points-x1-y1-and-x2-y2-take-the-points-from-user-22066

'Write a python program to compute the distance between the points (x1, Y1) and (x2, y2) Take the points from user:'

Florencia C.


*

Recommended Textbooks

-
Computer Science and Information Technology

Computer Science and Information Technology

Trishna Knowledge Systems 2018 Edition
achievement 1,027 solutions
Introduction to Programming Using Python

Introduction to Programming Using Python

Y. Daniel Liang 1st Edition
achievement 1,923 solutions
Computer Science - An Overview

Computer Science - An Overview

Glenn Brookshear, Dennis Brylow 12th Edition
achievement 1,648 solutions

*

Transcript

-
00:01 In this video, we are going to create a program that calculates the distance between two points.
00:05 I've written the distance formula on the upper right hand corner for a reminder.
00:10 I've also jotted down to examples, both that i've ran with the code word.
00:18 I'm going to write right now.
00:19 So looking at the code, i've already defined our class as well as the main method within it.
00:25 I've also imported java .util .scanner, since we know we'll be taking user input for the the points as well as java .lang .m.
00:33 Since we see square in a square root in some terms in our distance formula.
00:39 So we can go ahead into the main method.
00:41 We can create a new scanner object, calling an input, and using the predefined object system.
00:53 .in as an argument because this represents the standard input stream.
00:58 The next thing we'll want to do is prompt the user to and enter two points.
01:03 So we can use system .out .print l .n and say enter the first point.
01:16 So after this, we will want to use the next double method of the scanner input and create a double x1.
01:38 So this method of the scanner class scans the next token of the input as a double and we'll store them as such.
01:47 Same thing with x y1 my mistake so this is going to be our first point next we're going to want to print the same thing again asking the user to enter the second point again it's going to be the same with storing the user input so we can do double x2 and y2 next we can compute the distance to do this, we can go by our formula.
02:41 So i'm basically making in the comment just to show you math .com.
02:49 So it's going to be x2 minus x1 squared, so to the two...
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Join the community

18,000,000+

Students on Numerade


Trusted by students at 8,000+ universities

Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever