# biggerTwo challenge

Hi,

I am working on below challenge

http://codingbat.com/prob/p109537

i wrote as below
public int[] biggerTwo(int[] a, int[] b) {

int sum1=a[0]+a[1];
int sum2=b[0]+b[1];
if(sum1>sum2 | sum1==sum2)
return a;

else return b;
}

i passed all tests. I wonder how can i improve my code and alternate ways of doing it.
LVL 7
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
return a[0]+a[1]<b[0]+b[1]?b:a;
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Billing EngineerCommented:
if(sum1>sum2 | sum1==sum2)

could be simplified into:
if(sum1>=sum2 )

other than that, I see nothing that would make it more efficient
you could make it like this:
``````public int[] biggerTwo(int[] a, int[] b) {
return (  ( a[0]+a[1] < b[0]+b[1] ) ? b : a );
}
``````
but under the hood, it should result in the same cpu instructions...
0
Commented:
> how can i improve my code
I might use more homologous names, like suma, sumb, (or array1, array2)
and use >=  rather than repeating the comparison
0
Author Commented:
if(sum1>sum2 | sum1==sum2)
return a;

above is equalent to below right

if(sum1>=sum2)
return a;

if(sum1>sum2 & sum1==sum2)
return a;

above is equavelent to which one. Above cannot e written as below right?

if(sum1>=sum2)
return a;
0
Commented:
sum1>sum2 && sum1==sum2
is equivalent to
false
0
Billing EngineerCommented:
I agree with ozo, because a number cannot be at the same time be equal ( == ) or different, in this case higher ( > )
0
Author Commented:
so OR is the way to go not AND here got it.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.