While also works like for just you need to be manipulative with the initialization and conditions.
You can take a reference from this program.
public class WhileFactorial
public static void main(String args)
System.out.println("Enter a number");
Scanner in = new Scanner(System.in);
int num = in.nextInt();
while (num !=0)
fact = fact * num;
System.out.println("Factorial of the number is "+fact);