# Thread: [Java] How to do exponentiations?

1. Member
Join Date
Jan 2016
Posts
13
Rep Power
0

## [Java] How to do exponentiations?

Hey there!

I dont know how to do the exponentiations in java. I know how it works (math.pow(x,y)), but it aint so easy.
Code:
Java Code:
import java.util.Scanner;

public class Problem {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Please enter the loan in euros:  ");
double s = scan.nextDouble();

System.out.println("Please enter the loan period in years:  ");
double y = scan.nextDouble();

System.out.println("Please enter the interest rate in %:  ");
double p = scan.nextDouble();

double k = ( s * ( p / 100 / 12 )) / ( 1 - ( 1 + ( p / 100 / 12 )) ^ ( -y * 12 )); //i dont know how do the exponentation.
System.out.printf("%.2f" , k);

double t = k * y * 12;
System.out.printf("%.2f", t);

System.out.printf("With a loan of %.2d euros %.2d interest rate you have to pay %.2d + euros per month %.2d + years. You pay the pank a total of %.2d euros); //i want 2 decimal spaces but it doesnt do it.
}

}
The last printf() is also probobally wrong aswell, as i've used it before, but it doesnt change how the valuables are displayed. Help appreciated!
Last edited by Reviloest; 01-09-2016 at 01:58 PM.

2. ## Re: [Java] How to do exponentiations?

Java doesn't have an exponentiation operator; there's a statIC pow(x, y) method in the Math class for that purpose. Read the API documentation for that class and method for details.

kind regards,

Jos

ps. the arguments for that printf( ... ) method again don't make sense; read your other thread.

3. ## Re: [Java] How to do exponentiations?

Can you post the program's output and add some comments showing what is wrong with it and show what you want the output to look like?

#### Posting Permissions

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