Results 1 to 3 of 3
 10162014, 08:49 AM #1Member
 Join Date
 Oct 2014
 Posts
 1
 Rep Power
 0
using for loop to calculate power (ex... x^4)
i'm new to java and i'm trying to figure out how to calculate power in java using the for loop.
the geometric sequence is (d*c^(n1)).
so it goes d, d*c^1, d*c^2,......., d*c^(n1)
??????for (i=1; i<=n; i++){
result
}????????
please help, i don't understand how to program this. how do i write this using for loop?
 10162014, 09:13 AM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,423
 Blog Entries
 7
 Rep Power
 27
Re: using for loop to calculate power (ex... x^4)
Suppose you know the value x^(n1) and you are asked for the value x^n; take the previous value and multiply by x: x^(n1)*x == x^n; as you should know, x^0 == 1. This is what it looks like in code:
Java Code:double result= 1; for (int i= 0; i < n; i++) result*= x;
JosBuild a wall around Donald Trump; I'll pay for it.
 10162014, 09:18 AM #3Moderator
 Join Date
 Apr 2009
 Posts
 13,541
 Rep Power
 26
Re: using for loop to calculate power (ex... x^4)
Is that c^(n1), or (d*c)^(n1)?
Either way it doesn't really matter in terms of how to calculate the power using a loop, it just changes the start value.
So how would you do it by hand, for a value 'x' and a value of 'n'? Forget about code for the minute.Please do not ask for code as refusal often offends.
** This space for rent **
Similar Threads

calculate making problem while using while() loop in ResultSet
By raj.mscking@gmail.com in forum New To JavaReplies: 6Last Post: 06182012, 08:30 AM 
finding the power to a number then the user inputs a max a min power
By vicu1 in forum New To JavaReplies: 23Last Post: 11202011, 09:07 PM 
Using forloop and arrays to calculate factorials and fibonacci sequence
By baumboards in forum New To JavaReplies: 8Last Post: 03102011, 03:16 AM 
Power*MatchMaker 0.9.2
By JavaBean in forum Java SoftwareReplies: 0Last Post: 11272007, 08:21 PM
Bookmarks