Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Java Program Error

  Asked By: Live    Date: Apr 22    Category: Java    Views: 1649
  

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

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Dobra Lary     Answered On: Apr 27

change line
if((hh>=0 && hh<=23)||(mm>=0 && mm<=59)||(ss>=0 && ss<=59))
with
if((hh>=0 && hh<=23)&&(mm>=0 && mm<=59)&&(ss>=0 && ss<=59))

 
Didn't find what you were looking for? Find more on Java Program Error Or get search suggestion and latest updates.




Tagged: