Basic operation of Factorial Q
This commit is contained in:
HeshamTB 2020-10-15 06:26:53 +03:00
parent 425b1109a4
commit ad85cbea6c
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -0,0 +1,28 @@
import java.util.Scanner;
public class Factorials{
public static void main(String args[]){
String keepGoing = "y";
Scanner scan = new Scanner(System.in);
while (keepGoing.equals("y") || keepGoing.equals("Y")){
System.out.print("Enter an integer: ");
int val = scan.nextInt();
System.out.println("Factorial(" + val + ") = " + factorial(val));
System.out.print("Another factorial? (y/n) ");
keepGoing = scan.next();
}
}
private static int factorial(int value){
for (int i = value - 1; i > 0; i--){
value *= i;
}
return value;
}
}