We help IT Professionals succeed at work.
Get Started

maxMod5  challenge

210 Views
Last Modified: 2016-01-20
Hi,

I am working on below challenge
http://codingbat.com/prob/p115384

I tried my code as below
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;
  
}

Open in new window


I am getting below result
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

how to  improve my approach, results and design of this challenge. How do i make a graphical venn or flow chart or some other relevant diagram to design it before writing code to decide best strategy?
 Please advise
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 25 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE