troubleshooting Question

tenRun challenge

Avatar of gudii9
gudii9Flag for United States of America asked on
JavaJava EEProgramming Languages-OtherProgrammingProgramming Theory
28 Comments2 Solutions453 ViewsLast Modified:
Hi,

I am working on below challenge

http://codingbat.com/prob/p199484

Psedo code description of approach :
1. create new array of given array size
2. loop given array in for loop
3. check each element value not greater than 10
4. if yes multiply by 10
5 if no give same value from given array to new array

I wrote my code as below

public int[] tenRun(int[] nums) {
  
  
  int len =nums.length;
  int[] arr=new int[len];
  for(int i=0;i<len;i++){
    if(nums[i]<10){
    arr[i]=nums[i]*10;
    }
    else{
        arr[i]=nums[i];
    }
  }
  return arr;
}




I am  not passing all tests
Expected      Run            
tenRun([2, 10, 3, 4, 20, 5]) → [2, 10, 10, 10, 20, 20]      [20, 10, 30, 40, 20, 50]      X      
tenRun([10, 1, 20, 2]) → [10, 10, 20, 20]      [10, 10, 20, 20]      OK      
tenRun([10, 1, 9, 20]) → [10, 10, 10, 20]      [10, 10, 90, 20]      X      
tenRun([1, 2, 50, 1]) → [1, 2, 50, 50]      [10, 20, 50, 10]      X      
tenRun([1, 20, 50, 1]) → [1, 20, 50, 50]      [10, 20, 50, 10]      X      
tenRun([10, 10]) → [10, 10]      [10, 10]      OK      
tenRun([10, 2]) → [10, 10]      [10, 20]      X      
tenRun([0, 2]) → [0, 0]      [0, 20]      X      
tenRun([1, 2]) → [1, 2]      [10, 20]      X      
tenRun([1]) → [1]      [10]      X      
tenRun([]) → []      []      OK      
other tests
X      
How to improve my design, approach, code? 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 2 Answers and 28 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 2 Answers and 28 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