I have a starting value of 1000 This value must be multiplied by 1.5 (or 50%) for an x given amount of times. So for example: I want to multiply 1000 by 50% for 34 times. Example: 1000 > 1500 > 2250 > .... Please note that I'm using BigIntegers for this instead of normal Integers. I'm unable to figger this out in Java code. Any help would be great.
Just make a for loop and do this calculation in there. Something like this: Code (Text): double base = 1000; for(int i = 0; i < x; i++) base *= 1.5; If this is wrong tell me, it's a quick draft.
This isn't the way you would go about it. What @DizMizzer & @Photon suggests would be the appropriate way.
I'm quite sure that their way under the hood also uses a for loop. I could be wrong though. In my little time as a developer one of the few things I understood is that performance is everything! Thanks
Our way is faster because we aren't storing the variable over and over. This is also basic math not really programming
Test finished. Actually not as expected. Code (Text): 1 - Result: 1.9175105923288408E8. Operation took 768 nano seconds. 2 - Result: 1.9175105923288408E8. Operation took 13056 nano seconds. 1 = Your method @xTimPugz. 2 = @Photon 's method Code if you wanna try it yourself. EDIT: So basically, double as fast. Considerably faster for a computer, but not noticeable to a human eye. EDIT 2: @xTimPugz take a look at the edit. That's pretty odd. Your method proved to be faster. I just confused the results with my ignorance. EDIT 3: @DizMizzer , @xTimPugz 's method is actually faster
Thanks for all the help! I got it working. I'll have to think of a better formula to generate a required exp amount. When a player reaches level 90, it needs 9223372036854775807 (actual number) exp points to become level 91...
Well yeah I guess that's because under the hood 5 to the power of 5 is just the same as 5 * 5 * 5 *5 *5.
I don't really care about that haha I just want to enjoy my time on the forums and help around where I can hehe. Just thought it'd be helpful.