Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is this Console reading Code poor?  RSS feed

 
Miltos Tereres
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys. I know that Scanner exists but a professor at my university doesnt know that. He knows java 1.4 and believes that Scanner doesnt exist.
By the way in his book he has written a class to do the job.
Is it poor that he parses always the string to a double ?And then he casts the double to long int etc?

 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it's quite bad. A double has only limited precision, and the following code will show you why that is bad:
 
Miltos Tereres
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried putting max value and it worked. How ever maxvalue-5 doesnt work...
The problem is that this guy has printed a 500 page book about java
and forces his students to use this crappy class
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show him my example to prove him his code is wrong. The least he can do is custom parsing for all primitive types; that will also prevent input of a byte value of 255. In the current version that will truncate it to -1.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!