Files

17 lines
332 B
Java
Raw Permalink Normal View History

2025-10-28 22:04:54 -06:00
public class Test_2{
public int factorial(int n){
if(n < 0){
reutrn -1;
}
if (n == 0|| n==1){
return 1;
}
return n * factorial(n-1);
}
2025-10-28 23:17:27 -06:00
public static void main(String[] args) {
Test_2 obj = new Test_2();
int result = obj.factorial(5);
System.out.println("Factorial: " + result);
}
2025-10-28 22:04:54 -06:00
}