Try
public static void main(String[] args) {
int num;
int fact=1;
Scanner input = new Scanner(System.in);
System.out.println("Enter a number: ");
num = input.nextInt();
for (int i=2;i<=num; i++){
fact=fact*i;
}
System.out.println("Factorial: "+fact);
}
As @Marko Topolnik mentioned in comments this code will work for inputs up to 12. For larger inputs will output infinity due to overflow.
For numbers larger than 12 you should use higher data type like BigInteger
You can try:
public static void main(String[] args) {
BigInteger num;
BigInteger fact = BigInteger.valueOf(1);
Scanner input = new Scanner(System.in);
System.out.println("Enter a number: ");
num = input.nextBigInteger();
for (int i = 2; i <= num; i++){
fact = fact.multiply(BigInteger.valueOf(i));
}
System.out.println(fact);
}