Click here to Skip to main content
15,891,883 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Implement the factorial method for the given parameter n. Remember that 4!= 4*3*2*1. Use a for loop.

Java
public int p02Factorial(int n) {
  return 0;

Can someone walk me through how to do this?

What I have tried:

public int p02Factorial(int n) {
return 0;
Posted
Updated 9-Apr-16 19:42pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Apr-16 3:35am    
This is not a question, despite two question marks.
What you have tried won't even compile. This is not a decent effort. I doubt anyone would waste time for you, because it's hard to be sure that you would be able to use help.
—SA

Quote:
Can someone walk me through how to do this?
NO, this is your HomeWork, not ours.
You already know everything, the only thing left is writing the code.
Think about what you have been teached.
If really you can't find a solution yourself, speak with your teacher.
 
Share this answer
 
Comments
Member 12448577 10-Apr-16 1:00am    
-_-
Is it really that hard to look up your textbook to see what a for loop looks like ? I'll help you ...

Java
for (initialisation; termination; increment) 
{
    // statement(s) here
}


your issue is picking values for initialisation, termination, increment, as well as something useful for 'statement(s)'

So, given you're going to have some parameter value 'n', what do you think is a good bet for 'initialisation', hmmm ? what if I said, initialisation looks like

Java
for (int intMultiplier = n; termination; increment)
{
    // statement(s) here
}


is that enough to start with ?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900