Guest User

Java strange output

a guest
Apr 28th, 2026
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | Software | 0 0
  1. import java.util.Scanner;
  2. public class SimplePoint {
  3.    
  4.     private double x,y;
  5.  
  6.     public SimplePoint(double x1, double y1) {
  7.         x = x1;
  8.         y = y1;
  9.     }
  10.  
  11.     public double getX() { return x; };
  12.  
  13.     public double getY() { return y; };
  14.  
  15.     public double distance(SimplePoint p) {
  16.         return Math.sqrt( Math.pow(p.getX()-x,2) + Math.pow(p.getY()-y,2) );
  17.     }
  18.  
  19.     public static void main(String[] args){
  20.         Scanner input = new Scanner(System.in);
  21.         SimplePoint OriginPoint = new SimplePoint(0.0, 0.0);
  22.         double distance1, distance2, distance3, distance4;
  23.  
  24.         System.out.println("Enter four pairs of x,y coordinates:");
  25.         SimplePoint point1 = new SimplePoint(input.nextDouble(), input.nextDouble());
  26.         SimplePoint point2 = new SimplePoint(input.nextDouble(), input.nextDouble());
  27.         SimplePoint point3 = new SimplePoint(input.nextDouble(), input.nextDouble());
  28.         SimplePoint point4 = new SimplePoint(input.nextDouble(), input.nextDouble());
  29.        
  30.         distance1 = point1.distance(OriginPoint);
  31.         distance2 = point2.distance(OriginPoint);
  32.         distance3 = point3.distance(OriginPoint);
  33.         distance4 = point4.distance(OriginPoint);
  34.  
  35.         if (distance1 > distance2 && distance1 > distance3 && distance1 > distance4)
  36.             {System.out.printf("The point that's furthest from 0.0,0.0 is " + point1.getX() + "," + point1.getY() + " with distance: %.2f.", point1.distance(OriginPoint));}
  37.         else if (distance2 > distance1 && distance2 > distance3 && distance2 > distance4)
  38.             {System.out.printf("The point that's furthest from 0.0,0.0 is " + point2.getX() + "," + point2.getY() + " with distance: %.2f.", point2.distance(OriginPoint));}
  39.         else if (distance3 > distance1 && distance3 > distance2 && distance3 > distance4)
  40.             {System.out.printf("The point that's furthest from 0.0,0.0 is " + point3.getX() + "," + point3.getY() + " with distance: %.2f.", point3.distance(OriginPoint));}
  41.         else if (distance4 > distance1 && distance4 > distance3 && distance4 > distance2)
  42.             {System.out.printf("The point that's furthest from 0.0,0.0 is " + point4.getX() + "," + point4.getY() + " with distance: %.2f.", point4.distance(OriginPoint));}
  43.  
  44.     }    
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment