user2499376
user2499376

Reputation: 59

Simple Java Math

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); 
   }
}

Upvotes: 2

Views: 1348

Answers (3)

Ani
Ani

Reputation: 197

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); 
  }
}

Upvotes: -1

Matt Clark
Matt Clark

Reputation: 28589

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.

Upvotes: 7

jason
jason

Reputation: 241583

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.

Upvotes: 3

Related Questions