I am suppose to program a code to check whether the date is valid However my issue is over here is with the output. I am unable to display out if the user has input a valid/invalid date or month. T
String date;
int dd,mm,yyyy;
boolean leapyear,validdate;
if(mm >=1 || mm <=12) // to check if user input month which is less than 1 or more than 12
{
System.out.println(mm+" is an invalid month");
}
if((mm == 4 || mm == 6 || mm == 9 || mm == 11) && (dd <= 30)) // months with 30 days
{
validdate = true;
System.out.println(mm + "/" + dd + "/" + yyyy + " is a valid date.");
}
//For months with 31 days
else if((mm == 1 || mm == 3 || mm== 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) && (dd <= 31))
{
validdate = true;
System.out.println(mm + "/"+ dd + "/" + yyyy + " is a valid date.");
}
else
{
System.out.println("Invalid date!");
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire