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
    4

    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 online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,563
    Blog Entries
    7
    Rep Power
    21

    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
    cenosillicaphobia: the fear for an empty beer glass

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

    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 online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,563
    Blog Entries
    7
    Rep Power
    21

    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
    cenosillicaphobia: the fear for an empty beer glass

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, 05: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, 08:58 AM
  5. validate time input format
    By Alairmon in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 07: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
  •