• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

I'm looking if is there an other way how to check for an integer if a string and then ask the user

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then ask the user to enter a valid date this is my program thanks;
 
Marshal
Posts: 76802
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why have you posted in the GUIs forum when your question isn't about GUIs? Moving to a more appropriate location.

You have got the logic wrong for input from the keyboard. Yes, you need !myScanner.hasNextInt() but don't use an if‑else; use a loop:-But that will produce no end of code duplication. You would do better to put that loop in a method, and better still to put that method in a utility class which you can reuse for ever.Rob Spoor taught me that technique ages ago. It only works for one int at a time. You can overload that method to take onlly ints in a certain range.
 
Campbell Ritchie
Marshal
Posts: 76802
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please consider that you can shorten that isLeapYear() method to a single return statement, which you can use || or && to assemble.
Please consider the conditions you are missing in line 11.
 
Pay attention! Tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic