0

Trying to print out a^n but i get the error that a and n aren't defined as variables. Here is what I have now.

public class FermatsTheorem {

    public static void main(String[] args) {
        fermatsTheorem(a, n);
    }
    public static void fermatsTheorem(double a, double n){
        double aToTheNthPower = Math.pow(a,n);
        System.out.println("Fermat's Last Theorem: " + aToTheNthPower);
    }
}
7
  • 1
    Have you tried declaring them and giving them values? Sep 14, 2014 at 0:39
  • I plan to do that later, but for right now i want to set up a basic equation using the letters, so I want to print "a^n", except actually be up to the nth power.
    – Jaik
    Sep 14, 2014 at 0:42
  • 1
    a and n are just names for some values. If you don't give them any values then you might as well be trying to do John^Peter, it doesn't make sense
    – nem035
    Sep 14, 2014 at 0:43
  • 1
    You can't 'plan to do that later'. You can't even compile this code until you declare the variables. The compiler has already told you that. Your question and comment make no sense.
    – user207421
    Sep 14, 2014 at 4:09
  • I want to show the initial equation using a as a variable to show how it will be used when a value for it is later input and applied to the equation
    – Jaik
    Sep 14, 2014 at 4:57

2 Answers 2

1

You need to declare values for a and n.

Imagine you had an equation x + y = result. How could you know what the value of result is if you don't know the values of x and y?

Same thing for your case. You are trying to compute what a^n equals but you don't give the program any values to compute.

public class FermatsTheorem {

    public static void main(String[] args) {
        double a = 3.5;
        double n = 2.0;
        fermatsTheorem(a, n);
    }
    public static void fermatsTheorem(double a, double n){
        double aToTheNthPower = Math.pow(a,n);
        System.out.println("Fermat's Last Theorem: " + aToTheNthPower);
    }

}

0

You're looking for a Symbolic Manipulation. This is not a feature of most programming languages. You can't actually deal with abstracts, only concrete values. There are quite possibly libraries available to do what you want in your language of choice, but you may also want to look at something like Mathlab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.