(Coderbyte) First Factorial - Solução
Have the function FirstFactorial(num) take the num parameter being passed and return the factorial of it
(ie. if num = 4, return (4 * 3 * 2 * 1)). For the test cases, the range will be between 1 and 18.
Solução:
import java.util.*;
import java.io.*;
class Function {
int FirstFactorial(int num) {
int tmp = 1;
for (int i = 1; i <= num; i++) {
tmp *= i;
}
return tmp;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
Function c = new Function();
System.out.print(c.FirstFactorial(s.nextLine()));
}
}
Solução:
import java.util.*;
import java.io.*;
class Function {
int FirstFactorial(int num) {
int tmp = 1;
for (int i = 1; i <= num; i++) {
tmp *= i;
}
return tmp;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
Function c = new Function();
System.out.print(c.FirstFactorial(s.nextLine()));
}
}
Comments
Post a Comment