AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-programming: Program to print the shortest distance

Find the distance between the given coordinates X(x1, y1) and Y(x2, y2). The distance should be expressed correct to two decimal point.

Sample input:

4 15

75 5

Sample output:

71.70


corejava x 352
programming x 168
Posted On : 2018-01-28 08:44:07.0
profile Ananya - anyforum.in Ananya
4100
up-rate
1
down-rate

Answers


import java.util.Scanner;
import java.text.DecimalFormat;

class ShortDist
{
public static void main(String [] args){
int x1,y1,x2,y2,ans;
Scanner sc=new Scanner(System.in);
x1=sc.nextInt();
y1=sc.nextInt();
x2=sc.nextInt();
y2=sc.nextInt();
int ans1=Math.abs(x2-x1);
int ans2=Math.abs(y2-y1);
ans=((ans1 *ans1)+(ans2 * ans2));
DecimalFormat ft=new DecimalFormat("0.00");
System.out.println(ft.format(Math.sqrt(ans)));
}
}

Posted On : 2018-01-28 17:18:51
Satisfied : 2 Yes  0 No
profile Divesh - anyforum.in Divesh
101180
Reply This Thread
up-rate
3
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in