将点显示为有序对

时间:2014-09-10 04:15:19

标签: java math

我需要这个ASAP的答案。所以我在这个工作正常的一切我只需要在运行应用程序时显示我的x1,y1,x2,y2作为有序对。这就是我到目前为止所拥有的:

import java.util.Scanner; //class used for user input

public class PointSlope
{
    public static void main( String[] args )
   {

   // declare variables
   double x1;
   double y1;
   double x2;
   double y2;
   double slope;
   double distance;
   Scanner reader = new Scanner (System.in); // set up scanner
                                             // to read user inputs

  //store values in variables
  System.out.print ( "Enter x1" );
  x1 = reader.nextDouble();
  System.out.print ( "Enter y1" );
  y1 = reader.nextDouble();
  System.out.print ( "Enter x2" );
  x2 = reader.nextDouble();
  System.out.print ( "Enter y2" );
  y2 = reader.nextDouble();

  //calculate slope
  slope=(y2-y1)/(x2-x1);

  //calculate distance
  distance = Math.sqrt ((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2));

  //display result

  System.out.println ( "The distance between the 2 points is," + distance +
                      ",units" );
  System.out.println
                      ( "The slope of 2 points is," + slope +
                      ",units" ) ;

    }// end of class
} // end of class

1 个答案:

答案 0 :(得分:0)

你在谈论这样的事吗?

System.out.println 
                  ("("+x1+","+y1+")" );

  System.out.println 
                  ("("+x2+","+y2+")" );

显示为(x,y)?