Distance of two points

 Distance of two points

Problem Description

Write a program that prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distance between them.

Use Double Data Type and

String.format(" %.2f", outputValue);

Logic Test Case 1

Input (stdin)

2 3 4 5

Expected Output


Logic Test Case 2

Input (stdin)

2 1 3 4

Code Area

import java.io.*;

import java.util.*;

import java.lang.Math.*;

public class TestClass {

public static void main(String[] args) 


       Scanner s=new Scanner(System.in);

      int a=s.nextInt();

      int b=s.nextInt();

      int c=s.nextInt();

      int d=s.nextInt();

      double e=Math.sqrt((c-a)*(c-a)+(d-b)*(d-b));

      System.out.print(" "+Math.round(e*100.0)/100.0);




Post a comment