Results 1 to 5 of 5

Thread: I need some help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    19

    I need some help

    This is my first time in java. I was wondering if somebody could help me finish this. Thanks

    Recall that the distance between two points (x1,y1) and (x2, y2) is compute by taking the square root of the quanity (x1 - x2)^ + (y1 - y2)^.
    // *************************************************************
    // Distance.java
    //
    // Computes the distance between two points
    // *************************************************************
    import java.util.Scanner;
    public class Distance
    {
    public static void main (String[] args)
    {
    double x1, y1, x2, y2; // coordinates of two points
    double distance; // distance between the points
    Scanner scan = new Scanner(System.in);

    // Read in the two points
    System.out.print ("Enter the coordinates of the first point " +
    "(put a space between them): ");
    x1 = scan.nextDouble();
    y1 = scan.nextDouble();

    System.out.print ("Enter the coordinates of the second point: ");
    x2 = scan.nextDouble();
    y2 = scan.nextDouble();

    // Compute the distance

    // Print out the answer

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: I need some help

    Usually I'd say "We don't do homeworks" but what the hell today is a happy day
    Code:
      public static void main ( String[] args )
      {
        double x1, y1, x2, y2 ; // coordinates of two points
        double distance ; // distance between the points
        Scanner scan = new Scanner( System.in ) ;
    // Read in the two points
        System.out.print( "Enter the coordinates of the first point " +
    		      "(put a space between them): " ) ;
        x1 = scan.nextDouble() ;
        y1 = scan.nextDouble() ;
    
        System.out.print( "Enter the coordinates of the second point: " ) ;
        x2 = scan.nextDouble() ;
        y2 = scan.nextDouble() ;
        distance = Math.sqrt( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;
        System.out.printf( "The distance between (%f,%f) and (%f,%f)=%f", x1, y1,
    		       x2, y2, distance ) ;
      }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: I need some help

    Oh, and by the way to the Forums
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    19

    Re: I need some help

    Thank you very much

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: I need some help

    You could at least say, "Use code tags."
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width