Need Java Help...

<p>Hey everyone, I’m currently writing a JAVA program that involves exponential numbers, but I only really need the last 4 digits. Can anyone help me write some code for this?</p>

<p>For example, if x=123456, I only need 3456… You get the point. Thanks!</p>

<p>input n (your number)
input x (your power)
for(i=0; i <x; i++)
{
n = n*n;
}</p>

<p>I just ran it and I’m pretty sure that doesn’t work… In your code, there is no restriction on how long n can be… (grows pretty quickly :))</p>

<p>darmani’s code is the code to calculate expontentials itself.</p>

<p>i don’t know whether or not this will work since i haven’t programmed since the end of senior year, but it might, and if not, maybe it’ll give you a good idea how to go.</p>

<p>int n= number;
int j=10, k=0, z=0;
for(int c=0; c<4;c++) //my favorite coding line cause C++ rules JAVA
{
z=n%j;
k+=z;
n-=z;
j=j*10;
} return k;</p>

<p>ill just parasitize off of this thread here…</p>

<p>i need to write a java program that calculates newtons method. it would be great is someone could write up a pseudocode or the actual code for me. you could just pm it to me.</p>

<p>thanks</p>

<p>you could easily just make it into a string and take the last 4 chars. Math.pow is exponential btw.</p>