Problem link:
Discuss: you can solve the problem in many way. but java is naive one. if you know about java BigInteger function and how it works. then just find factorial using any loop. but one thing to cite in uva you must have Class type as Main(M is in capital letter). and there is no tricky part in this problem.
try yourself, before see the code
import java.math.BigInteger;
import java.util.Scanner;
class Main{
public static void main(String[] args) {
Scanner in= new Scanner (System.in);
while(in.hasNext()) {
long n,i;
n=in.nextInt();
BigInteger fact=BigInteger.ONE;
for(i=1; i<=n; i++) {
fact=fact.multiply(BigInteger.valueOf(i));
}
System.out.println(n+"!");
System.out.println(fact);
}
}
}
Discuss: you can solve the problem in many way. but java is naive one. if you know about java BigInteger function and how it works. then just find factorial using any loop. but one thing to cite in uva you must have Class type as Main(M is in capital letter). and there is no tricky part in this problem.
try yourself, before see the code
import java.math.BigInteger;
import java.util.Scanner;
class Main{
public static void main(String[] args) {
Scanner in= new Scanner (System.in);
while(in.hasNext()) {
long n,i;
n=in.nextInt();
BigInteger fact=BigInteger.ONE;
for(i=1; i<=n; i++) {
fact=fact.multiply(BigInteger.valueOf(i));
}
System.out.println(n+"!");
System.out.println(fact);
}
}
}
No comments:
Post a Comment