Can anybody help me with a Java program?

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

Kyteland

Diamond Member
Dec 30, 2002
5,747
1
81
Originally posted by: Bacardi151
well that's how i interpreted the problem, that he wanted to separate positive even, positive odd, and negative to its respective arrays
You didn't say "positive even." You just called it evenList. If your prof said positive even then you are right. If they didn't then it probably wouldn't hurt to ask for clarification.
 

Kyteland

Diamond Member
Dec 30, 2002
5,747
1
81
Originally posted by: MAME
Originally posted by: Kyteland
Originally posted by: MAME
an infinite for loop = for( ;;; )

and people can easily put a 100+ lines of code in a loop but shouldn't. It's a bad programming practice. God invented functions for a reason.
Fixed. ;)

100 function calls!
I'd be willing to bet you could break those 100 function calls down further. ;)

My rule of thumb is that if I can't see the entire function on the screen (1200x1600 with 12pt font is ~80 lines of text) then it is a candidate for refactoring in to smaller modules.
 

MAME

Banned
Sep 19, 2003
9,281
1
0
Originally posted by: Kyteland
Originally posted by: Bacardi151
well that's how i interpreted the problem, that he wanted to separate positive even, positive odd, and negative to its respective arrays
You didn't say "positive even." You just called it evenList. If your prof said positive even then you are right. If they didn't then it probably wouldn't hurt to ask for clarification.

it doesn't matter...the OP is hopelessly lost and it's 3 months too late anyway
 

Kyteland

Diamond Member
Dec 30, 2002
5,747
1
81
Originally posted by: MAME
it doesn't matter...the OP is hopelessly lost and it's 3 months too late anyway
:Q Jeebus! I bet he passed his procrastination class with flying colors.
 

Bacardi151

Senior member
Dec 15, 2003
540
0
0
Originally posted by: Kyteland
Originally posted by: Bacardi151
well that's how i interpreted the problem, that he wanted to separate positive even, positive odd, and negative to its respective arrays
You didn't say "positive even." You just called it evenList. If your prof said positive even then you are right. If they didn't then it probably wouldn't hurt to ask for clarification.

heh, just to clarify, this isnt my program, i just bumped up a very old thread.
 

jman19

Lifer
Nov 3, 2000
11,221
654
126
Originally posted by: MAME
Originally posted by: Bacardi151
Originally posted by: MAME
Originally posted by: Bacardi151
i have no experience with reading/updating other peoples code so i can't comment on that.

but sometimes you're forced to use while loops, if there's no fixed number of iterations, although in this case there is.

but imagine if the program was to ask for an integer input until the person put in a specific value which means quit. you wouldn't be able to implement that using a for loop.

instead you use an if statement to check if the specified exit value/string, is inputted and if it is, then you get out of the loop by a break statement. i really dont see the hardship in reading that.

FYI: for loops are while loops, thus anything a while loop can do, a for loop can as well

If you want to control input from a user, you could do:
while(input != (exiting input) )

There nothing overly horrible with your example, but it's just small scale. Think if the code was production level, say 1,000 lines of code for one loop. You don't want to trace every break statement and condition

I can speak with my teachers if you'd like, but assuming I pass my Art History final in 5 hours, I won't likely seem them in person ever again come wednesday ;)


well how do you suggest you do an infinite loop with a for loop? set the limit to a very large number? it seems impractical, or perhaps you set it to something that will never be true. such as (for i = 0; i < -1; i++) , but yet again, it seems impractical. and the break statement is obviously put at the very top next to an if statement because that's the first thing you should check before doing any unnecessary computations. and i doubt anybody puts 1000 lines of code inside a while loop, let alone 100.

an infinite for loop = for( ;;; )

and people easily put a 100+ lines of code in a loop

er, wouldn't an infintely for loop be "for( ;; )"?
 

MAME

Banned
Sep 19, 2003
9,281
1
0
Originally posted by: jman19
Originally posted by: MAME
Originally posted by: Bacardi151
Originally posted by: MAME
Originally posted by: Bacardi151
i have no experience with reading/updating other peoples code so i can't comment on that.

but sometimes you're forced to use while loops, if there's no fixed number of iterations, although in this case there is.

but imagine if the program was to ask for an integer input until the person put in a specific value which means quit. you wouldn't be able to implement that using a for loop.

instead you use an if statement to check if the specified exit value/string, is inputted and if it is, then you get out of the loop by a break statement. i really dont see the hardship in reading that.

FYI: for loops are while loops, thus anything a while loop can do, a for loop can as well

If you want to control input from a user, you could do:
while(input != (exiting input) )

There nothing overly horrible with your example, but it's just small scale. Think if the code was production level, say 1,000 lines of code for one loop. You don't want to trace every break statement and condition

I can speak with my teachers if you'd like, but assuming I pass my Art History final in 5 hours, I won't likely seem them in person ever again come wednesday ;)


well how do you suggest you do an infinite loop with a for loop? set the limit to a very large number? it seems impractical, or perhaps you set it to something that will never be true. such as (for i = 0; i < -1; i++) , but yet again, it seems impractical. and the break statement is obviously put at the very top next to an if statement because that's the first thing you should check before doing any unnecessary computations. and i doubt anybody puts 1000 lines of code inside a while loop, let alone 100.

an infinite for loop = for( ;;; )

and people easily put a 100+ lines of code in a loop

er, wouldn't an infintely for loop be "for(;;)"?

yeah, one too many ;'s