guys, I'm trying to read a stream of numbers from standard input like: 2 3 -3 10 44 9 -1. The line ends once it read -1, but for some reason I have an endless loop... how could I read this stream of numbers one number at a time?

guys, I'm trying to read a stream of numbers from standard input like: 2 3 -3 10 44 9 -1. The line ends once it read -1, but for some reason I have an endless loop... how could I read this stream of numbers one number at a time?

Really? Your approach would be to make a dedicated instance method to invoke on an object that has no real purpose? You'd manually read a token using scanner.next() and *then* parse it as an integer? You'd compare the input to -1 via string equality rather than just comparing integers? You have two identical return statements when one could just be replaced by a break?

Because in larger codes static methods are bad, when trying to trouble shoot code on an enterprise level. Besides I'd assume this method would be used inside a class without a main() lol.

So what's the big deal, reading in a string from the user and parsing it to an Integer... I didn't break any coding rules, one can use either or... and who cares that I used a 'return' instead of a break they can be used interchangeably in this instance.

July 25th, 2012, 12:17 AM

veeer

Re: reading a stream of numbers from standard input

Static methods are bad? So Math.sin is bad, eh? I understand what you're trying to say, but this is clearly not enterprise scale... you appear to have to some degree a naive understanding of unit testing via mocking. Not trying to start a fight, just pointing out flaws in your code. You can choose to acknowledge them.