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!
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!
// 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]
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?
pow takes doubles. Is it really so hard to search for the "Math" class in the API docs?
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!!
can you help me create this program?
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.)
4 years ago they might have helped you create it. Now - doubtful. But I'm sure nobody else is going to help you. And btw, you don't use Math.pow() to generate random numbers.
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.
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);
}
}
(int) Math.pow(a,n) = (int) Math.pow((p(1+ r)),n)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.