Brandon Baldanza wrote:7. Accept the odd number from the keyboard and store it in the variable called number2.
9. Divide number2 by 2 and store the result in number3.
Ganesh Patekar wrote:did you notice, you may loose precision here
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Please read this The Arithmetic Operators, If still get problems, you are welcomeBrandon Baldanza wrote:Correct im stuck on line 8, not sure how I can write that line of code to "Multiply number1 by 100, divide the result by 10 and then add 5 to that result. Store the result in intResult." My teacher didn't really show us how to do that in class, the book im using isnt very clear either.
line 8 saysBrandon Baldanza wrote:Would this work for line 8? int intresult = number1 * 100 / number1 + 5;
Biggest problem im facing is how to store the result in the correct place.
there is no issue of loss of precision as result is in int.Ganesh Patekar wrote:but remember loss of precision.
Can you please tell me the reason why we should not close it, I really have no notion about it ? Actually I also never closed that but OP made me ponder on thatCampbell Ritchie wrote:Never never never close a Scanner pointing to System.in or similar. Not even if Eclipse complains about resource leaks.
OP did; look at line 30.Ganesh Patekar wrote:. . . Actually I also never closed that but OP made me ponder on that
Yes I know OP closed that. I couldn't convey what I meant, please bear my poor English writingCampbell Ritchie wrote:OP did; look at line 30.
Will be a nightmare for me, realised the reason of your fervent statement Never * 3Campbell Ritchie wrote:What do you think will happen if you close that Scanner?
Java 8 SE Doc wrote:Closes this scanner.
If this scanner has not yet been closed then if its underlying readable also implements the Closeable interface then the readable's close method will be invoked. If this scanner is already closed then invoking this method will have no effect. Attempting to perform search operations after a scanner has been closed will result in an IllegalStateException.
My pleasure. Thank you for confirming what classes Scanner uses in the background; I had never looked in the source. It uses an input stream reader but not a buffered reader.Ganesh Patekar wrote:. . . Thank you for precious advice