J
Johnny
I'm just starting to learn Java and I'm trying to write some code for
computing a factorial. (That the mathmatical expression for a number
to it's own power). I'm writing this with Sun One studio 4. Here is
what I have, the problem is that it's not working. When I enter 3 I
get back 81 (should get 27), when I enter 4 I get 65536 (should get
256):
public class Factorial
{
public static void main(String[] args)
{
int x,y,q;
Keyboard kbd;
kbd = new Keyboard();
y=1;
System.out.println("Please enter a number you'd like the factorial
for");
q=kbd.readInt();
x=q;
if (q==0)
{
System.out.println("The factorial is 1");
}
else
{
while (y<q)
{
y=y+1;
x=x*x;
}System.out.println("The factorial is "+x);
}
}
}
Any suggestions?
If possible please email me at (e-mail address removed)
computing a factorial. (That the mathmatical expression for a number
to it's own power). I'm writing this with Sun One studio 4. Here is
what I have, the problem is that it's not working. When I enter 3 I
get back 81 (should get 27), when I enter 4 I get 65536 (should get
256):
public class Factorial
{
public static void main(String[] args)
{
int x,y,q;
Keyboard kbd;
kbd = new Keyboard();
y=1;
System.out.println("Please enter a number you'd like the factorial
for");
q=kbd.readInt();
x=q;
if (q==0)
{
System.out.println("The factorial is 1");
}
else
{
while (y<q)
{
y=y+1;
x=x*x;
}System.out.println("The factorial is "+x);
}
}
}
Any suggestions?
If possible please email me at (e-mail address removed)