Results 1 to 8 of 8
Thread: Simple code not working
- 02-04-2011, 01:27 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Simple code not working
Hello everyone. I can't figure out what is wrong with my code. It seems really dumb.
Java Code:int i = 0; int stupid_int_cuz_java_is_being_dumb = 0; while(i < array.length) { while(i < array.length && array[i] != true) { i++; } System.out.println("I " +i); if(i > (i - stupid_int_cuz_java_is_being_dumb)) { stupid_int_cuz_java_is_being_dumb = i; } System.out.println(stupid_int_cuz_java_is_being_dumb); i++; }
Last edited by davetheant; 02-04-2011 at 01:28 AM. Reason: Unclear
- 02-04-2011, 01:30 AM #2
This makes no sense at all. Can you please explain what you are trying to do. Also write a SSCCE using meaningful names. I have no idea what stupid_int_blahblahblah is supposed to represent.
- 02-04-2011, 01:33 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Oh sorry I forgot that I had 'array' there. Array is a one-dimensional array of booleans (they are all false to begin with). I am trying to return an array that is identical, except that it changes the middle of the longest sequence of unoccupied places to true. So it should change the 5th element to true.
- 02-04-2011, 01:38 AM #4
Member
- Join Date
- Jan 2011
- Location
- Gainesville, FL
- Posts
- 45
- Rep Power
- 0
- 02-04-2011, 01:39 AM #5Java Code:
if(i > (i - stupid_int_cuz_java_is_being_dumb))
But I still maintain that none of this makes sense even after your explanation.
- 02-04-2011, 01:46 AM #6
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
while(i < array.length)
while(i < array.length && array[i] != true)
array is a one-dimensional array of booleans.
- 02-04-2011, 01:48 AM #7
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Can we delete this thread? I figured it out
- 02-04-2011, 01:51 AM #8
I've taken a closer look at your code.
> i is 0
> stupid is 0
> i is less than 10 (I'm assuming that is the length of your boolean array) so outer while condition is true
> i is still less than 10 and boolean at array[0] is false so inner while condition is true
> i is incremented to 10 when it exits due to i not being less than 10 anymore.
> print I 10
> As mentioned above the if statement is false because 10 is not greater than 10 - 0
> print 0
> increment i to 11
> 11 is not less than 10 outer while condition fails
> Done
Once again your code does not make sense.
Similar Threads
-
\n not working in GUI (working code, but \n isn't working)
By cc11rocks in forum New To JavaReplies: 2Last Post: 01-04-2011, 05:30 AM -
Why is the code not working
By sanox in forum New To JavaReplies: 12Last Post: 09-08-2009, 12:28 PM -
Simple TCP chat application not working for me
By sundarrajan in forum New To JavaReplies: 0Last Post: 08-13-2009, 09:31 AM -
JNI: Why this code not working?
By playwin2 in forum Advanced JavaReplies: 5Last Post: 11-25-2008, 02:12 PM -
simple validations not working
By rahaman.athiq in forum Web FrameworksReplies: 0Last Post: 11-06-2008, 07:10 AM
Bookmarks