2

So I know that this is super simple, and I'm sorry for having to ask this on here. Unfortuntely, I am confused and have no one else to ask...

Anyway, I'm trying to use Java to solve the following equation:

 __________________
√ (3.1^17 + 2.7^11)

The code that I have right now doesn't work. It is:

public class Math
{
    public static void main(String[] args)
    {
        double a = 3.1
        double b = 2.7;

        double c = Math.sqrt(Math.pow(a,17) + Math.pow(b,11));

        System.out.println(c); 
   }
}
8
  • 8
    "doesn't work" - is not a real question. Commented Jun 23, 2013 at 3:36
  • What does not work about this code? Stack traces? Commented Jun 23, 2013 at 3:37
  • Consider using an IDE, such as Eclipse, to ease your semantic troubles. Commented Jun 23, 2013 at 3:41
  • 2
    I so don't agree with the trigger-happy closing of questions like this. It's blatantly obvious at a quick glance what is wrong with this code. Given that, there's an opportunity to help someone. Commented Jun 23, 2013 at 3:47
  • 1
    In the future you should at least include the error message you get, or if there isn't any, a description of what the code does when you run it and what it should do. That way people don't have to guess. The same applies wherever you ask programming questions, not only Stack Overflow. Commented Jun 23, 2013 at 8:51

3 Answers 3

7

Your class name is Math, you are trying to call Math.function, which does not exist in your class, you need to refactor your class name and import the class library.

Right click the file name, Refactor > Rename

If your class must be named math, you must call:

java.lang.Math.pow();

Another problem is that you are missing a ; after:

double a = 3.1

Fix both of these problems and you will have a working code!

In the future, please post stack traces and specific problems are having.

Sign up to request clarification or add additional context in comments.

4 Comments

No, this is not the main issue.
I found the main issue and added it to the answer. I saw this first error first as for me it would not even compile. I then noticed their class name was Math and that the real math lib was not imported.
It still won't compile even if you fix the semicolon, so your suggestion that you found the issue after fixing the semicolon is dubious.
I did not copy the entire code, as I already had a project setup in eclipse, I just copied the body of main
3

Don't name your class Math, you need to give it a different name from the Java framework class Math. Also, you need to fix double a = 3.1 to have a semicolon at the end and add import java.lang.Math.

Comments

-1
import java.lang.Math;
public class maths
{
public static void main(String[] args)
{
    double a = 3.1;
    double b = 2.7;

    double c = Math.sqrt(Math.pow(a,17) + Math.pow(b,11));

    System.out.println(c); 
  }
}

2 Comments

Welcome to Stack Overflow! Would you mind explaining what you changed in the code and why?
classname couldn't be a methodname. java.lang.Math should be imported.Also the semicolon.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.