Re: Java Assignment Problem.
This is what happens in your code:
1. n is supplied by user. for example user input 5.
2. you create a variable call index and you give the initial value to 40.
3. you have this condition check while (index < n); translated into while (40 < 5); this while will never get executed. because 40 is not less than 5.
4. because the while block doesn't get executed it simply return 1; the initial value you gave to sum variable.
So first fix this while block. you should not give 40 as the initial value of index. Increment the index simply mean add some number to the index.