dateFashion

From ggc

Jump to: navigation, search

http://www.javabat.com/prob?id=Logic.dateFashion


public int dateFashion(int you, int date) {

 If(you >=8 || date >=8)
 {
 return 2;
 }
 else if(you <=2 || date <=2)
 {
 return 0;
 }
 return 1;

}



I feel like I almost have it but I cant even get it to run. Says I need a ; after >=8 but thats not right when i put one there

Answer: It had more to do with your placement of when you check for 8 and when you check for 2. You should have done the check for 2 before the check for 8 because if you do the check for 8 first it can cause a {return 2;} for a value of 8 , 2 when it should just return 0.

Also your 'else' needs to go after the {return 0;}


Solution

public int dateFashion(int you, int date) {

 if (you <=2 || date <=2)
{return 0;}
 else
if (you >= 8 || date >= 8)
{return 2;}  
else
{return 1;}

}





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter