Why is this statement used: fact*=i;
. I can't understand because I am a beginner. Is there some other way that we can write the same statement in a while loop?
//This is my program for factorial using input from user.
import java.io.*;
public class factorialInput {
public static void main(String[] args) throws IOException {
int i = 1;
int fact = 1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter any number:");
int n = Integer.parseInt(br.readLine());
while (i <= n) {
fact *= i;
i++;
}
System.out.println("Factorial of" + n + "!" + "=" + fact);
}
}