HI,

I need some help on using the math.pow() function to solve the following problem:

a^n = p(1+ r)^n

how would I translate it using math.pow()

Thanks for your suggestions and any help!

webmasts
0
Newbie Poster

HI,

I need some help on using the math.pow() function to solve the following problem:

a^n = p(1+ r)^n

how would I translate it using math.pow()

Thanks for your suggestions and any help!

Jump to Post`// pow(x, y) returns the x raised // to the yth power. System.out.println("pow(2.0, 2.0) is " + Math.pow(2.0,2.0)); System.out.println("pow(10.0, 3.5) is " + Math.pow(10.0,3.5)); System.out.println("pow(8, -1) is " + Math.pow(8,-1));`

[IMG]http://img476.imageshack.us/img476/5171/cut20ln.png[/IMG]

Piworld ™

[Tis simple as Pie]

Jump to PostSo to check If I understand, let say 6 raised to the power of 4 6^4 would be coded like this:

math.pow(6, 4) do I have to use it in this form...6.0 and 4.0 using double? Will Int work?

Yes..

taking int values will work but then you have to …

Jump to PostA further development of extemer's program leads to the following table showing the furture values of one thousand dolloars investment calculated based on compound interest: a(t) = (1 + i)^t where i is rate while t the number of years

`import java.text.DecimalFormat; import javax.swing.*; import javax.swing.JTextArea.*; class …`

iamthwee

```
// pow(x, y) returns the x raised
// to the yth power.
System.out.println("pow(2.0, 2.0) is " + Math.pow(2.0,2.0));
System.out.println("pow(10.0, 3.5) is " + Math.pow(10.0,3.5));
System.out.println("pow(8, -1) is " + Math.pow(8,-1));
```

[IMG]http://img476.imageshack.us/img476/5171/cut20ln.png[/IMG]**Piworld ™**

[Tis simple as Pie]

webmasts
0
Newbie Poster

So to check If I understand, let say 6 raised to the power of 4 6^4 would be coded like this:

math.pow(6, 4) do I have to use it in this form...6.0 and 4.0 using double? Will Int work?

Edited
by Dani because:
*
Formatting fixed *

Phaelax
52
Practically a Posting Shark

pow takes doubles. Is it really so hard to search for the "Math" class in the API docs?

psodhi
0
Newbie Poster

So to check If I understand, let say 6 raised to the power of 4 6^4 would be coded like this:

math.pow(6, 4) do I have to use it in this form...6.0 and 4.0 using double? Will Int work?

Yes..

taking int values will work but then you have to cast the Math.pow() method to return int valus..because it returns double value by default.

e.g., int a=(int)Math.pow(6,4);

Hope it would help u understand the method!!

gulaygulay2000
0
Newbie Poster

Create a Java program called FindThatNumber. java. The program should generate 10 random integers between 1 and 100 (inclusive) using Math.pow( ) and then store them sequentially in an array. The program should then ask the user to enter a single integer. If the integer is in the array just entered, the program should respond “Bingo!”; otherwise, the program should respond “Sorry”. The program should continue running until the user enters -999 to quit. (Hint: The code (int) (100 * Math.random( ) + 1) creates the required random number.)

BestJewSinceJC
700
Posting Maven

extemer
-17
Junior Poster
Banned

i recently done a program very much same to your ask question

it works on foramula a=p(1+r)^n.check it out and look that if it can help you and if any question you can ask.

```
import java.text.DecimalFormat;
import javax.swing.*;
import javax.swing.JTextArea.*;
class TextAreaDemoB
{
public static void main(String[] args){
double amount,
p=1000.0,
rate=.05;
DecimalFormat pre= new DecimalFormat("0.00");
JTextArea out= new JTextArea(0,0);
out.append(" year\tamount\n");
for(int year=1; year<=10; year++)
{
amount=p * Math.pow( 1.0 + rate , year );
out.append( year + "\t" +
pre.format( amount )+ "\n" );
}
JOptionPane.showMessageDialog(null,out," note",JOptionPane.INFORMATION_MESSAGE);
}}
```

remember for taking power of any value you can use Math.pow class.

Edited
by peter_budo because:
*
Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags *

peter_budo
commented:
Reopening old threads and posting rubbish code, bad!
-3

tong1
22
Posting Whiz

A further development of extemer's program leads to the following table showing the furture values of one thousand dolloars investment calculated based on compound interest: a(t) = (1 + i)^t where i is rate while t the number of years

```
import java.text.DecimalFormat;
import javax.swing.*;
import javax.swing.JTextArea.*;
class TextAreaDemoB {
public static void main(String[] args){
double amount,
p=1000.0,
rate=.025;
DecimalFormat pre= new DecimalFormat("0.00");
DecimalFormat preRate= new DecimalFormat("0.000");
JTextArea out= new JTextArea(0,0);
out.append(" year, rate->\t");
for (int j=0;j<10;j++)
out.append(preRate.format(rate+j*0.025)+ "\t");
out.append("\n");
for(int year=1; year<=10; year++) {
out.append( year + "\t");
for (int j=0; j<10; j++){
amount=p * Math.pow( 1.0 + (rate+j*0.025) , year );
out.append(pre.format( amount )+ "\t" );
}
out.append("\n");
}
JOptionPane.showMessageDialog(null,out,"Future values of $1000 investment with various numbers of years and rates",JOptionPane.INFORMATION_MESSAGE);
}
}
```

Donkerster
-3
Newbie Poster

(int) Math.pow(a,n) = (int) Math.pow((p(1+ r)),n)

Ezzaral
commented:
Why did you resurrect this thread to post this nonsense?
-3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.