We help IT Professionals succeed at work.
Get Started

array sum2 challenge

Last Modified: 2015-07-02

i am trying  below challenge


i tried as below
public int sum2(int[] nums) {

int numsSum[]=new int[4];

return nums[0]+nums[1];

//  else (nums.length==1)
 // return nums[0];
  return 0;

Open in new window

Expected	Run		
sum2({1, 2, 3}) → 3	3	OK	    
sum2({1, 1}) → 2	2	OK	    
sum2({1, 1, 1, 1}) → 2	2	OK	    
sum2({1, 2}) → 3	3	OK	    
sum2({1}) → 1	0	X	    
sum2({}) → 0	0	OK	    
sum2({4, 5, 6}) → 9	9	OK	    
sum2({4}) → 4	0	X	    
other tests

Open in new window

i failed few tests. How to fix and improve my code. please advise
Watch Question
Most Valuable Expert 2014
Top Expert 2015
This problem has been solved!
Unlock 3 Answers and 26 Comments.
See Answers
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