What is a eul- Chegg study import java .util. Scanner public class TestFactorial
ID: 3574421 • Letter: W
Question
What is a eul- Chegg study import java .util. Scanner public class TestFactorial Main method public static v main(stringli args) f Create a Scanner Scanner input new scanner(system. in)i system out. print("Enter a non-negative integer: int n input .nextInt(); Display factorial system. out.println("Factorial of n is t factorial(n)); input close(); Return the factorial for a specified number public static long factorial (int n) if (n 0) Base case return 1; else return n factorial (n 1); Recursive caLL cps 223Explanation / Answer
import java.util.Scanner;
public class TestFunction {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.print("Please enter a non negative integer:");
int n = scan.nextInt();
System.out.println("New Factorial of "+n+" is "+newfactorial(n));
}
private static int newfactorial(int n) {
// TODO Auto-generated method stub
if(n==0)
{
return 0;
}
return n+newfactorial(n-1);
//return null;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.