• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Input error

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Recently, I tried making my own calculator but I ran into some errors...


I listed out my problem with comments in the code listed..

Any help would be appreciated

Thanks!
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Good thing you found the code button, but please indent the code inside the code tags, too.

Just before the offending line, add a line for testing which prints out the int which you have just read (I think snum). Does that give the right value?
What have you been told nextLine() does? Did anybody tell you it reads the next line? Does your book tell youit reads the next line? Becuase it doesn’t. It tells you something different here, but it may not be clear. If you read something and then call nextLine(), it reads the remainder of the line. As you will see from this message, it can even read a zero‑length line. Which doesn’t do you much good. In that sort of instance, you need the enter key be pressed before the prompt. The simplest thing to try to call nextLine() and discard its return value before trying to display the prompt.
 
yakabuff bob
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please point me in a general direction of removing the return value of nextLine()?


Thanks
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. You can’t remove the return value. You simply don’t use it. You write myScanner.nextLine(); as a whole line, and the return value disappears into a sort of cyber‑limbo never to be seen again.
Didn’t it say that in the old thread I quoted? Try here.
 
yakabuff bob
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I replace "myscanner".nextLine() with my own variable?
 
yakabuff bob
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So do I just replace "myscanner".nextLine() with my own variable?


Thanks
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yakabuff bob wrote:So I replace "myscanner".nextLine() with my own variable?

Not quite. You might have to call input.nextLine() twice and only assign it to your own variable second time.
 
yakabuff bob
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for helping me

My book had always said that nextLine() was a scanner for strings though..

Guess I misinterpreted it..
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You’re welcome
I told you a lot of books get that bit wrong.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello! I have returned after 9 years of intensive research and I can say with confidence that i am now an expert Java calculator developer
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Input errors: Gives the total number of no buffer, runts, giants, CRCs, frame, overrun, ignored, and abort counts. Other input-related errors can also increment the count, so this sum might not balance with the other counts.Input errors: Includes runts, giants, no buffer, CRC, frame, overrun, and ignored counts. Other input-related errors can also cause the input error count to be increased, and some datagrams may have more than one error; therefore, this sum may not balance with the sum of enumerated input error counts.

Greeting,
Rachel Gomez
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RG: welcome to the Ranch

Please explain the relevance of your post to the rest of this thread.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic