package org.interview.test;
import java.util.Scanner;
public class Factorial {
public static void main (String [] args) throws Exception {
findFactorial();
}
public static Integer findFactorial() {
int n , fact = 1;
Scanner sc = new Scanner(System.in);
System.out.println("Enter number to calculate Factorial: ");
n = sc.nextInt();
for (int i = 1 ; i <= n ; i++) {
fact *= i;
}
System.out.println("Factorial: " + fact);
return fact;
}
}
import java.util.Scanner;
public class Factorial {
public static void main (String [] args) throws Exception {
findFactorial();
}
public static Integer findFactorial() {
int n , fact = 1;
Scanner sc = new Scanner(System.in);
System.out.println("Enter number to calculate Factorial: ");
n = sc.nextInt();
for (int i = 1 ; i <= n ; i++) {
fact *= i;
}
System.out.println("Factorial: " + fact);
return fact;
}
}
No comments:
Post a Comment