Possible Duplicate:
How to return multiple objects from a Java method?
lets say N= a+b;
for a number N i want to generate the all possible values a and b. like
if N =7 a and b are (1+6),(2+5),(3+4).
i have coded this logic in a method.
static void sumofNum(int N){
for(int a=1; a<N; a++){
//a+b=N
int b = N-a;
System.out.println(a+","+b);
int next =a+1;
if(next==b | a==b)
return;
}
}
i want to return (1,6),(2,5),(3,4) from this method. next for any N there can be more (a,b) combinations to be returned from this method.
If you want to return them as ints, define a object that contains two ints (or abuse points as I have done below) and return a list of those objects. If you define your own object, just replace point with that.
You can get your results from the list with: