Please help me, I cannot find the error in the following code. Boolean always returs true in the following program.
class time
{
int hh, mm, ss;
public time()
{
hh = 0;
mm = 0;
ss = 0;
}
public time(int h, int m, int s)
{
hh = h;
mm = m;
ss = s;
}
public boolean validate()
{
boolean valid = false;
if((hh>=0 && hh<=23)||(mm>=0 && mm<=59)||(ss>=0 && ss<=59))
valid=true;
return valid;
}
public void display()
{
if(hh>12)
hh=hh-12;
System.out.println("Your time is: "+ hh+":"+ mm +":"+ ss);
}
public static void main(String args[])
{
time ob = new time(20,55,30);
if (ob.validate()==true)
ob.display();
else
System.out.println("Invalid format");
}
}
http://live-project-training.in