Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Square root not working

Threaded View

  1. #1
    Member
    Join Date
    Oct 2010
    Posts
    38
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default Square root not working

    This is my program that does the distance formula for you. I don't understand why it can't find the method for doing square root unless that changed? My code is here and the error is below it.

    import java.lang.Math;
     
    public class Distance_Formula {
     
    	public static void main(String [] args) {
     
    		userInput input = new userInput();
    		double x1 = 0.0;
    		double x2 = 0.0;
    		double y1 = 0.0;
    		double y2 = 0.0;
    		double distancePreSquareRoot = 0.0;
    		double distancePostSquareRoot = 0.0;
    		String x1prompt = "Enter the X1 value: ";
    		String x2prompt = "Enter the X2 value: ";
    		String y1prompt = "Enter the Y1 value: ";
    		String y2prompt = "Enter the Y2 value: ";
     
    		input.getUserInput(x1prompt);
    		x1 = Double.parseDouble(input.input);
    		input.getUserInput(x2prompt);
    		x2 = Double.parseDouble(input.input);
    		input.getUserInput(y1prompt);
    		y1 = Double.parseDouble(input.input);
    		input.getUserInput(y2prompt);
    		y2 = Double.parseDouble(input.input);
     
    		distancePreSquareRoot = (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
     
    		distancePostSquareRoot = sqrt(distancePreSquareRoot);
     
    		System.out.println("The distance between (" + x1 + "," + y1 + " and (" + x2 + "," + y2 + ") is: " + distancePostSquareRoot);
     
     
    	}
     
    }

    Error:

    Distance_Formula.java:30: cannot find symbol
    symbol  : method sqrt(double)
    location: class Distance_Formula
                    distancePostSquareRoot = sqrt(distancePreSquareRoot);
                                             ^
    1 error
    Press any key to continue . . .
    Last edited by sp11k3t3ht3rd; January 7th, 2011 at 06:14 PM.


Similar Threads

  1. JAVA MAGIC SQUARE
    By hiimjoey11 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: November 28th, 2012, 12:42 AM
  2. Latin square logic
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2010, 09:38 AM
  3. Finding square root
    By Tracy22 in forum The Cafe
    Replies: 1
    Last Post: October 18th, 2010, 06:18 PM
  4. Java program Square root
    By Hey in forum Java Theory & Questions
    Replies: 5
    Last Post: August 16th, 2009, 01:14 AM
  5. Replies: 4
    Last Post: January 27th, 2009, 12:03 AM