fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.math.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. Point A1 = new Point(0,3);
  15. Point A2 = new Point(2,0);
  16. Point B = new Point(0,0);
  17.  
  18. System.out.println(
  19. B.distance(A1,A2)
  20. );
  21. }
  22. }
  23.  
  24. class Point {
  25. double x,y;
  26.  
  27. Point(double x, double y){
  28. this.x= x;
  29. this.y= y;
  30. }
  31.  
  32. public double distance(Point A1, Point A2){
  33. double numerator = Math.abs((A2.y - A1.y)*this.x + (A2.x - A1.x)*this.y + A2.x*A1.y - A2.y*A1.x);
  34. double denominator = Math.sqrt(Math.pow(A2.y - A1.y,2) + Math.pow(A2.x - A1.x,2));
  35.  
  36. return numerator/denominator;
  37. }
  38.  
  39. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
1.6641005886756874