public static int factorial(int number){
//base case
if(number == 0){
return 1;
}
return number*factorial(number -1);
}
public static int factorial(int number){
int result = 1;
while(number != 0){
result = result*number;
number--;
}
return result;
}
}
//base case
if(number == 0){
return 1;
}
return number*factorial(number -1);
}
(OR)
int result = 1;
while(number != 0){
result = result*number;
number--;
}
return result;
}
}
No comments:
Post a Comment