Results 21 to 21 of 21
Thread: Java Assignment Problem.
- 12-07-2012, 02:54 AM #21
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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
Similar Threads
-
problem with assignment
By frickenj in forum New To JavaReplies: 9Last Post: 05-08-2011, 05:02 PM -
problem with java assignment
By jaire in forum New To JavaReplies: 9Last Post: 03-10-2011, 11:00 AM -
Problem with my assignment - in need of help!
By Chopaan in forum New To JavaReplies: 1Last Post: 01-17-2011, 02:19 AM -
While Loop Problem with Java Assignment Program
By welsh_rocker in forum New To JavaReplies: 9Last Post: 01-12-2011, 01:55 PM -
The Assignment Problem
By bumblyb33 in forum New To JavaReplies: 5Last Post: 03-04-2009, 04:21 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks