Question

In: Computer Science

Factorials in Java: Write out your Program Design for how to automate the testing. The objective...

Factorials in Java: Write out your Program Design for how to automate the testing. The objective is to repeat the factorial calculation for different values of n, as n changes from 2, 3, 4, 5, 6, 7..

1) test for an int

2) test for a long

3)test for a double

Solutions

Expert Solution

Code:

import java.util.*;
class sample
{
   public static void main(String args[])               //main method
   {
       Scanner scan=new Scanner(System.in);           //object creation for scanner
       int n=scan.nextInt();                   //taking input n from user to what extent i've to perform factorial
       long fact=1;                      
       System.out.println("Integers");
       for(int i=2;i<=n;i++)                   //iterating loop from 2 to n integers
       {
           fact=fact*i;                   //finding factorial
           System.out.println(i+"    "+fact);       //printing factorial
       }
       long fact1=1;
       System.out.println("Long integer");
       for(long i=2;i<=n;i++)                   //iterating loop from 2 to n long integers
       {
           fact1=fact1*i;                   //finding factorial
           System.out.println(i+"    "+fact1);       //printing factorial
       }
       double fact2=1;
       System.out.println("Double");
       for(double i=2;i<=n;i++)               //iterating loop from 2 to n doubles
       {
           fact2=fact2*i;                   //finding factorial
           System.out.println(i+"    "+fact2);       //printing factorial
       }
   }
}


Related Solutions

Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project Details: Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make...
Language is Java Design and write a Java console program to estimate the number of syllables...
Language is Java Design and write a Java console program to estimate the number of syllables in an English word. Assume that the number of syllables is determined by vowels as follows. Each sequence of adjacent vowels (a, e, i, o, u, or y), except for a terminal e, is a syllable. However, the minimum number of syllables in an English word is one. The program should prompt for a word and respond with the estimated number of syllables in...
Throwing Exceptions - JAVA File Factorials contains a program that calls the factorial method of theMathUtils...
Throwing Exceptions - JAVA File Factorials contains a program that calls the factorial method of theMathUtils class to compute the factorials of integers entered by the user. Save these files to your directory and study the code in both, then compile and run Factorials to see how it works. Try several positive integers, then try a negative number. You should find that it works for small positive integers (values < 17), but that it returns a large negative value for...
using Dr java Objective: Write a program that takes a phrase and then counts the number...
using Dr java Objective: Write a program that takes a phrase and then counts the number of vowels (case does not matter) in the phrase. It then should display all of the vowels in sorted ascending order according to their count. Only consider {AEIOU} as the vowels. Hint: It may be a good idea to keep track and sort two arrays: Has the vowels in alphabetic order Has the number of said vowels Whenever one would swap then it swaps...
Objective: Write a program in java to give a student directions for whether they should report...
Objective: Write a program in java to give a student directions for whether they should report to school or learn online based on their response to several questions. Your program should model the HNA hybrid requirements of reporting to school for: Mondays, Thursdays: Last name A-K Tuesdays, Fridays: Last name L-Z Odd week Wednesday: A-K Even week Wednesday L-Z Ask the user the day of week, followed by their last name. In the case that the day of the week...
How to write IO program in java?
How to write IO program in java?
Write a complete Java program to print out the name bob
Write a complete Java program to print out the name bob
Write a C program that evaluates the factorials from 1 to 5. Print results in a...
Write a C program that evaluates the factorials from 1 to 5. Print results in a tabular format.
please use java swing and recursion and the suggested method hints listed Objective: Write a program...
please use java swing and recursion and the suggested method hints listed Objective: Write a program in which draws (yes it actually makes a picture) a triangular fractal using recursion. This is best if done using a java applet. Suggested Methodology The idea for it is this First draw a filled equilateral triangle Next draw another filled equilateral triangle of a different color that’s upside down in the middle of that triangle Using the other triangles formed repeat step 2...
Create a program in JAVA that displays a design or picture for someone in your quarantine...
Create a program in JAVA that displays a design or picture for someone in your quarantine household/group: a pet, a parent, a sibling, a friend. Make them a picture using the tools in TurtleGraphics and run your program to share it with them! Use a pen object, as well as any of the shape class objects to help you create your design. You must use and draw at least 5 shape objects. - You must use a minimum of 4...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT