Results 21 to 21 of 21
- 12-07-2012, 02:54 AM #21Senior Member
- Join Date
- Jun 2007
- Bali, Indonesia
- Rep Power
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.Website: Learn Java by Examples
- By frickenj in forum New To JavaReplies: 9Last Post: 05-08-2011, 05:02 PM
- By jaire in forum New To JavaReplies: 9Last Post: 03-10-2011, 11:00 AM
- By Chopaan in forum New To JavaReplies: 1Last Post: 01-17-2011, 02:19 AM
- By welsh_rocker in forum New To JavaReplies: 9Last Post: 01-12-2011, 01:55 PM
- By bumblyb33 in forum New To JavaReplies: 5Last Post: 03-04-2009, 04:21 AM