troubleshooting Question

hasOne challenge

Avatar of gudii9
gudii9Flag for United States of America asked on
JavaJava EEProgrammingProgramming TheoryGame Programming
59 Comments3 Solutions496 ViewsLast Modified:
Hi,

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

Psedo code:
1. for given number % with 10
2. if 1 return true
3. else return false

I wrote my code as below

public boolean hasOne(int n) {
  if(n%10==1){
  
 // if(n/10==1){
  return true;
 // }
  }
  return false;
  
}



I am not passing all tests
Expected      Run            
hasOne(10) → true      false      X      
hasOne(22) → false      false      OK      
hasOne(220) → false      false      OK      
hasOne(212) → true      false      X      
hasOne(1) → true      true      OK      
hasOne(9) → false      false      OK      
hasOne(211112) → true      false      X      
hasOne(121121) → true      true      OK      
hasOne(222222) → false      false      OK      
hasOne(56156) → true      false      X      
hasOne(56556) → false      false      OK      
other tests
X      

How to improve/modify my design, code and any other alternate approaches. please advise
ASKER CERTIFIED SOLUTION
d-glitch
Research Engineer - Electrical

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 59 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 59 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros