• 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

Runtime Error - Need Help

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I'm working on some code for an assignment and I'm receiving a runtime error. Our professor provided us with the I/O code for the program and we only had to complete the code for max_cycle_length(); I've attached the code below.

Can someone help me figure out what could be causing this error? I cannot figure it out; the code performs the calculations correctly, but I can't get the program to terminate without throwing an exception. Thanks for any help - let me know if I need to post more info.

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This program will stop when your "readLine" method returns null, which will happen on end-of-file. On Windows, you can type an end-of-file character using Ctrl-Z; on UNIX, Ctrl-D.

So two questions for you: first, what does max_cycle_length compute, exactly? And second, an instructor actually gave you the other code to use as scaffolding?
 
Amy Lee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
max_cycle_length() computes the maximum cycle length inclusive and between two integers based on the 3n + 1 problem (Collatz Problem - see MathWorld.com).

Yes, the instructor gave us all the I/O code. The only code block we had to write was max_cycle_length().

I typed in <Ctrl> + Z and got back a NumberFormatException. Previously, I tried typing in -1 and got back a NoSuchElementException. I also tried hitting <ENTER> and I got back a NoSuchElementException as well.

It seems no matter what I type in I get some sort of an exception.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please post the EXACT error message you recieve? This will include information that we need to be able to help you further.

Layne
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amy Lee:
...Yes, the instructor gave us all the I/O code. The only code block we had to write was max_cycle_length()....



I wonder why your instructor provided this code? The Java API already has a readLine() method in the BufferedReader class that is probably much more efficient than the implementation your instructor gave.

Layne
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic