lab-03:
Basic operation of Factorial Q
This commit is contained in:
parent
425b1109a4
commit
ad85cbea6c
28
lab-03/src/Factorials.java
Normal file
28
lab-03/src/Factorials.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user