Results 1 to 5 of 5
  1. #1
    arunjib is offline Member
    Join Date
    Mar 2011
    Location
    West Bengal
    Posts
    29
    Rep Power
    0

    Default boolean time format

    what is the error of the following code? why it always returns true?

    Java Code:
        public boolean validate()
        {
            boolean valid = false;       
            if((hh>=0 || hh<=23)&&(mm>=0 || mm<=59)&&(ss>=0 || ss<=59))
            valid=true;
            return valid;
        }

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    5

    Default

    Hi. what did you enter for variables mm, ss, hh?
    Now It looks correct.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,051
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by arunjib View Post
    what is the error of the following code? why it always returns true?

    Java Code:
        public boolean validate()
        {
            boolean valid = false;       
            if((hh>=0 || hh<=23)&&(mm>=0 || mm<=59)&&(ss>=0 || ss<=59))
            valid=true;
            return valid;
        }
    If, say, ss == 4242 it is larger than zero ...

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    393
    Rep Power
    5

    Default

    Also, you can just "return ((hh>=0......". No need to create a variable to hold it, if all it does is return it. And if you really want the variable to return, you can use "boolean valid=((hh>=0...".

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,051
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by Toll View Post
    Also, you can just "return ((hh>=0......". No need to create a variable to hold it, if all it does is return it. And if you really want the variable to return, you can use "boolean valid=((hh>=0...".
    That doesn't address the problem at all and doesn't solve it either. Read my first reply for a hint of the problem (and the solution).

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. boolean error help when no boolean is given
    By drewtrcy in forum New To Java
    Replies: 18
    Last Post: 05-05-2011, 09:04 AM
  2. Replies: 1
    Last Post: 02-02-2011, 06:39 AM
  3. input masking 24hour time format (hh:nn) to jTextField
    By newbiejava in forum New To Java
    Replies: 2
    Last Post: 07-24-2010, 01:12 PM
  4. Convert String to Time format
    By plasma in forum New To Java
    Replies: 1
    Last Post: 12-16-2009, 09:58 AM
  5. validate time input format
    By Alairmon in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 08:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •