We help IT Professionals succeed at work.

Return 2 int values

gauravflame
gauravflame asked
on
423 Views
Last Modified: 2012-05-05
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;
   }
   
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

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

int[]
it doesn't mean we are returning the two int arrays , not two integers
Java Architect
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>it doesn't mean we are returning the two int arrays , not two integers

It means you're returning two ints in an array
Bart CremersJava Architect

Commented:
int[] means returning a single int array containing an unspecified number of ints.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
a bean as Bart_Cr suggests is typically the way to go.
using an array is somewhat error prone
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>using an array is somewhat error prone

In what way?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.