Jump to content


- - - - -

java date


  • You cannot reply to this topic
2 replies to this topic

#1 jamaicarocks

    TMN Friend

  • Members
  • PipPipPipPipPipPip
  • 297 posts

Posted 06 October 2007 - 08:51 PM

good day,

                I am designing a program in Java and want users to enter their birth month, entering a number between 1-12, which represents Jan to  Dec ..........then prints out the Month which corresponds to the number they entered.

The problem I'm having is Java's month starts at January corresponding to number 0.
How could I change this, or see instructions to change this.

Thank you

#2 fr0stbound

    Expert

  • Members
  • PipPipPipPipPipPipPip
  • 1,292 posts

Posted 07 October 2007 - 12:50 AM

to put it crudely, store the user input in a variable. subtract 1 from the value, then use the result to process output.

therefore, if user inputs 1, store to variable a, then subtract 1. that will make it as though the user input(inputted? i don't know the past tense) 0. and so on for other numbers.

sorry if it was hard to understand, i don't know how to program with java(yet). do you know c? if you want, i'll give you a sample source code.

also, a tip, since this is the hardest to do at beginner level programming. make sure you make an error catching sort of module, in case the user inputs a wrong value. in your case, it will be inputting a month higher than 12. my teacher taught me this the hard way. a simple nested if-then statement will do the job.

#3 jamaicarocks

    TMN Friend

  • Members
  • PipPipPipPipPipPip
  • 297 posts

Posted 07 October 2007 - 01:44 AM

Thanks alot,will try your suggestion, a sample code would have helped a lot.I will use whats known as a Toolbox in Java to kinda restrict what the users can enter.

thanks so far





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users