Sum Of Factorials

Feb 10, 2014

The first method returns the factorial of an integer (factorial of 3 = 1x2x3). And the second returns the sum of the factorials between 2 integers. This is correct according to my professor. I'm just confused as to why in the 2nd methods it isn't "total = total + Factorial(i);" instead of what I have.

public class LoopProblems
{
public int Factorial (int n){
int total = 1;
for (int i = 1; i <= n ; i++ ) {
total = total * i;
}
return total; 
}
 public int SumOfFactorials (int start, int end) {

[code]....

View Replies


ADVERTISEMENT

Calculating Factorials Using BlueJ

Oct 7, 2014

I am trying to calculate factorials using BlueJ. All of my factorials calculate correctly, I am just having an issue with something the instructor asked of us. She asked us to force the loop to stop when the user inputs "Calculate the factorial of 0", and not give any print.

So far I have my for loop with the correct conditions, I am just really confused as to how to make an if statement to stop the code when the input is 0.

View Replies View Related

Program That Computes Factorials Up To 50?

Mar 8, 2014

I have to write a program that computes factorials up to 50

public static void main(String[] args) {
int [] a= new int [100];
for(int n=0; n<=50; n++) {
double factorial = 1;
for (int multiplier=1; multiplier<=50; multiplier++)

[Code] ....

I have this as my code so far I just don't know how to incorporate the array in there which i need to do as well as I dont get why all the output comes out for every single thing . IT will write 1 factorial and display all the factorials up to 50 and do the same pattern over and over again.

View Replies View Related

Finding Factorian - Sum Of All Factorials

Apr 10, 2014

I have written the following code to try and find a factorian but it doesn't work all the time. A factorian is supposed to be the sum of the factorials.

public static boolean isFactorion(int n){
boolean rv = false;
int sum =0;
int fact = 1;
for(int i = n;i>=1;i--){
fact = fact * i;

[Code] ......

View Replies View Related

Calculate Factorials Of Numbers 1 Through 10 - Validating Input

Sep 13, 2014

I'm trying to write a program that calculates the factorials of the numbers 1 through 10, based on user input... My problem is that I don't know how to address the possibility of the user entering something other than a number. When I test the following code by entering a letter, I get an Input Mismatch exception. I'd like to be able to inform the user that the entry is invalid, and ask for another response. Here is my program thus far:

Java Code:

import java.util.Scanner;
public class Factorial {
public static String entryString;
public static char entryChar;
public static Scanner input = new Scanner(System.in);

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved