• 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

parseInt for using a blank line for sentinel

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm attempting to set the sentinel in my program as a blank line, but I'm unsure how to go about it except to say that I feel certain parseInt is involved in the process. Can anyone explain to me how to use a blank line for a sentinel?

 
Marshal
Posts: 79180
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

You can’t use parseInt because that requires a String which represents an int. If you want to use a blank line as a sentinel, you can use its length() method, or there is a new (Java6+) method in the String class called isEmpty(). If the length is 0 or the String is empty, then you have a blank line. You can use the trim() method on a line which starts or ends with whitespace, to shorten it.
 
Joshua Amy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much for this!



Campbell Ritchie wrote:Welcome to the Ranch

You can’t use parseInt because that requires a String which represents an int. If you want to use a blank line as a sentinel, you can use its length() method, or there is a new (Java6+) method in the String class called isEmpty(). If the length is 0 or the String is empty, then you have a blank line. You can use the trim() method on a line which starts or ends with whitespace, to shorten it.

 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You’re welcome
reply
    Bookmark Topic Watch Topic
  • New Topic