Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Factorial loop help

Ok so I need to find the smallest integer whose factorial is greater than 2000

current code:
public class FactorialInt {
public static void main (String args[]){

int value = 7, factorial = 1, temp= value;

while(temp > 0){
factorial *=temp;
temp--;
}
System.out.println("The factorial of " + value + " is " + factorial + ".");
}}

not sure how to change this code to solve problem. I can find the factorial for a int that i set but i how do i have it find the int that meets the requirements?

2. ## Re: Factorial loop help

how do i have it find the int that meets the requirements?
Brute force? Start with 3 and go from there until you've found the int that meets the requirements.

3. ## Re: Factorial loop help

i did that and its 7, bit the program is to i guess run a loop that finds that number

4. ## Re: Factorial loop help

The loop needs to keep changing the number until the desired results are found.

5. ## Re: Factorial loop help

not sure how to make that happen since i have a loop going already, do i add another loop or does my current loop need to be changed?

6. ## Re: Factorial loop help

Have a loop that starts at 1 and changes the factor until the desired result.
Save the last factorial and use for next computation.

7. ## Re: Factorial loop help

public class FactorialInt {

public static void main (String args[]){
int input_number = 0;
int factorial = 1;

while (factorial < 2000){
input_number = input_number + 1;
factorial = factorial * input_number;
}
System.out.println( "The Factorial of " + input_number+ " is " + factorial );
}
}

this seems to work please check!

8. ## Re: Factorial loop help

this seems to work
If you get the correct results, then that solves it.