1) Write a program FindFactorial that computes and displays the factorial of a n
ID: 3538462 • Letter: 1
Question
1) Write a program FindFactorial that computes and displays the factorial of a non-negative integer. For example, the factorial of 4 is computed as 4 * 3 * 2 * 1 = 24. The factorial of 5 is computed as 5 * 4 * 3 * 2 * 1 = 120. In general, the factorial of n is n * n-1 * n-2 * n-3 * %u2026 * 1
2) 4. Write a class FindMinMaxAverage that computes and displays the minimum, maximum and average value of n random integers with values from 0 to 500 (inclusive). The value of n should be entered by the user.
Explanation / Answer
import java.util.Scanner; public class FindFactorial { public static void main(String args[]) { int n, c, fact = 1; System.out.println("Enter an integer to calculate it's factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if ( n < 0 ) System.out.println("Number should be non-negative."); else { for ( c = n ; c >= 1 ; c-- ) { fact = fact*c; if(c!=1) System.out.print(c+"*"); else System.out.print(c); } System.out.println("="+fact); } } } import java.util.Scanner; import java.lang.*; public class FindMinMaxAverage { public static void main(String args[]) { int i,n,minimum=0, maximum=0, average=0,random,sum=0; //Random rn = new Random(); System.out.println("Enter an integer"); Scanner in = new Scanner(System.in); n = in.nextInt(); for(i=0;imaximum) { maximum = random; } else if(randomRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.