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
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
Guy Hengel [angelIII / a3]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 );
}

Open in new window

but under the hood, it should result in the same cpu instructions...
ozoCommented:
> 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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

gudii9Author 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;
ozoCommented:
sum1>sum2 && sum1==sum2
is equivalent to
false
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I agree with ozo, because a number cannot be at the same time be equal ( == ) or different, in this case higher ( > )
gudii9Author Commented:
so OR is the way to go not AND here got it.
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.