I’m taking the if-else statement this week and I trying to solve the question but I’m still getting an error message. Can anyone tell me what I’m doing wrong? Remember that this is an if-else question but other methods will be also appreciated.
Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. Given a variable modelYear write a statement that prints the message
RECALLto standard output if the value of modelYear falls within those two ranges.
if(modelYear==1995||modelYear==1998)
{
System.out.println("Recall");
}
else if(modelYear==2004||modelYear==2006)
{
System.out.println("Recall");
}
it means that models from [1995, 1996, 1997, 1998] and [2004, 2005, 2006], these years should be recalled.
Your condition:
means that only two years in range are counted. models from [1996 and 1997] won’t be recalled.
To include both the ranges you can do following:
OR
You should create a separate method to check the ranges: