public int maxMod5(int a, int b) {
if(a>b){
return a;
}
else{
if( (a==b)){
return 0;
}
else if( (b%5==a%5)){
return 0;
}
}
return 1;
}
Expected Run
maxMod5(2, 3) → 3 1 X
maxMod5(6, 2) → 6 6 OK
maxMod5(3, 2) → 3 3 OK
maxMod5(8, 12) → 12 1 X
maxMod5(7, 12) → 7 0 X
maxMod5(11, 6) → 6 11 X
maxMod5(2, 7) → 2 0 X
maxMod5(7, 7) → 0 0 OK
maxMod5(9, 1) → 9 9 OK
maxMod5(9, 14) → 9 0 X
maxMod5(1, 2) → 2 1 X
other tests
OK
ASKER
if(a==b){
return 0;
}
else if(a%5==b%5){
return Math.min(a,b);
}
return Math.max(a,b);
ASKER
if(a==b){
return 0;
}
else if(a%5==b%5){
return Math.min(a,b);
}
return Math.max(a,b);
public int maxMod5(int a, int b) {
if(a%5==b%5){
return Math.min(a,b);
}
else if( (a==b)){
return 0;
}
else {
return Math.max(a,b);
}
}
ASKER
public int maxMod5(int a, int b) {
if(a%5==b%5){
return Math.min(a,b);
}
else if( (a==b)){
return 0;
}
else {
return Math.max(a,b);
}
}
Expected Run
maxMod5(2, 3) → 3 3 OK
maxMod5(6, 2) → 6 6 OK
maxMod5(3, 2) → 3 3 OK
maxMod5(8, 12) → 12 12 OK
maxMod5(7, 12) → 7 7 OK
maxMod5(11, 6) → 6 6 OK
maxMod5(2, 7) → 2 2 OK
maxMod5(7, 7) → 0 7 X
maxMod5(9, 1) → 9 9 OK
maxMod5(9, 14) → 9 9 OK
maxMod5(1, 2) → 2 2 OK
other tests
X
Correct for more than half the tests
ASKER
What you need to think about is when the ints are the same and you run the mod test first.
public int maxMod5(int a, int b) {
if(a==b){return 0;}
if(a%5==b%5){return Math.min(a,b);}
else {return Math.max(a,b);
}
}
ASKER
Ask yourself what happens when a==10 and say b==20.
if(a==b){
return 0;
}
else if(a%5==b%5){
return Math.min(a,b);
}
ASKER
However, in all cases,in the challenge i have to read above more clearly.
ASKER
public int maxMod5(int a, int b) {if code as above i see why below is failing
if(a%5==b%5){
return Math.min(a,b);
}
else if( (a==b)){
return 0;
}
else {
return Math.max(a,b);
}
}
ASKER
ASKER
understanding the wording is important.
ASKER
So cases that should return "0" are the most particular, so deal with them first
ASKER
how do i conclude some sentence(out o . . . . .
ASKER
HOWEVER, if it's after 3 o'clock
Is my understanding is correct?
ASKER
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.
TRUSTED BY
Open in new window