Link to home
Start Free TrialLog in
Avatar of gauravflame
gauravflame

asked on

Return 2 int values

How to return the two integer values in Java terms


int getnumber(int a ,int b)
   {
       number1 = a;
       number2 = b;
       
       //return new int[]{number1,number2};
       //return number1 , number2;
   }
   
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gauravflame
gauravflame

ASKER

int[] getnumber(int a ,int b) {

int[]
it doesn't mean we are returning the two int arrays , not two integers
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>it doesn't mean we are returning the two int arrays , not two integers

It means you're returning two ints in an array
int[] means returning a single int array containing an unspecified number of ints.
a bean as Bart_Cr suggests is typically the way to go.
using an array is somewhat error prone
>>using an array is somewhat error prone

In what way?