Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

importjava.util.InputMismatchException;
importjava.util.Scanner;
publicclassMphasis{
publicstaticvoidmain(String[]args){
Scanners=newScanner(System.in);
System.out.println("enteranumber:");
intn=s.nextInt();
if(n<0){
thrownewInputMismatchException("Thenumbershouldnotbenegative");
}
System.out.println(factorial(n));
}
privatestaticintfactorial(intn){
if(n==1||n==0){
return1;
}
returnn*factorial(n-1);
}
}
3 months ago