This is a factorial program in java, its not working please let me know the errors. Thanks!
class Fact {
public static void main(String[] args) {
int i=5,num=1;
while(i>1) {
num=num*i;
}
i--;
System.out.println("Value: " + num);
}
}
You decrease the variable
ioutside of thewhileloop when it’s supposed to be inside of it.Should be:
What your current code says is that
while *i* is greater than 1 do your multiplication. The problem is that i will always be greater then 1 since you never substract from it.