Computer Science, asked by chandana1101, 2 months ago

WAP to display the distance between 2 points on a line using d=√(x²-x¹)³ + (y² - y¹)²

java , using scanner class​

Answers

Answered by BrainlyProgrammer
4

Correct Formula:-

 \sqrt{ {( {x}_{2}  - {x}_{1} )}^{2}  +{( {y}_{2}  - {y}_{1} )}^{2}}

Required Answer:-

import java.util.*;

class Distance {

public static void main (String ar []){

Scanner sc=new Scanner (System.in);

System.out.println("Enter 1st coordinate");

int x1=sc.nextInt();

int y1=sc.nextInt();

System.out.println("Enter 2nd coordinate");

int x2=sc.nextInt();

int y2=sc.nextInt();

double d=0.0;

d=Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2));

System.out.println("Distance="+d);

}

}

Similar questions