Hey guys,
I have this HW for school for Java but I just can't seem to figure it out. I know I have to use a for loop for it but I just can't seem to figure out everything else. Thanks :D

use a for loop, and have an answer variable that is set to 1. then decrement the for loop, and then multiply the number in the for loop to the number in the answer, and once you are done return the answer.

I just did this but can you guys please explain why its this?

public class bob
{
public static void main(String args[]) {
int n=7;
int fact=1;
for(int i=1; i<=n; i++)
{
fact=fact*i;
}
System.out.println (fact);
}
}

no. instead of adding you want to subtract. and the n is the factorial (in your case 7, so 7 x 6 x 5 x 4 x 3 x 2 x 1). so you want to use n in your for loop. and you want to decrement to follow the pattern. then your fact value if your answer, so the operation would look like this

no. instead of adding you want to subtract. and the n is the factorial (in your case 7, so 7 x 6 x 5 x 4 x 3 x 2 x 1).

I don't understand why you have rejected the OP's solution just because it computes the answer in the order 1 x 2 x 3 x 4 x 5 x 6 x 7. The end result is that same.

@xiangzhuang: "I just did this but can you guys please explain why its this?"
That's a very strange question. If you just did that you must know why you did it that way. Is it possible that you copied that code form someone/somewhere else?

I thing the OP was asking why this (solution) works.
Whether you are looping from 1 to 7, or 7 down to 1, makes no difference.
You're just multiplying everything together.

I'm sorry I didn't notice that.. It doesn't make a difference because when you multiply the order doesn't matter. it is only when you are adding and multiplying in the same command. for example if you multiply 5 x 4 x 3 you get 60, and if you do (5 x 5) + 5 which gives an answer of 30, or if you do 5 * (5 + 5) which gives you an answer of 50. This is the reason BEDMAS was created.

Also the reason I rejected it was because factorials go from the highest number down. So I wanted to keep the factorial method the same as what a factorial is, but it doesn't actually matter.

@carlosreg: That's just a scruffy version of the code that xiangzhuang posted earlier in this thread, except that his version works and yours does not.
You can avoid much embarrassment by (a) reading the whole thread and (b) testing your code for elementary errors before posting.

Write a program that displays all numbers divisible by 3 and 4 within a range entered by user. Display five numbers per line. Numbers are separated by exactly two spaces. ...

Hi guys. I am trying to create a program where the user inputs an integer and the program will cout the nth prime number. Unfortunatly when I try to cout ...

Hello Friends,
I Developed application in C# with crystal reports and created setup file in third party (Advance) Installer.When i installed my application on client system application is working but ...