Total Answers: 4 [Go Back]
Make a class that contains the result and return a member of this class.
Mon, 06 Feb 2012 09:26:46 GMT
If im understanding you correctly, you want to create a function that returns two values? Ive never done java before but whenever I run into a problem in vb.net that requires two things to be returned, I return one with the function and in a way return the other via reference.
the method with a variable such as Int loopCount 0; Function ThisIsYourFunction(ByRef loopCount) Do Some loops loopCount++ SomeOtherMathHere Return yourReturnValue Since loopCount was passed by reference anything you do to it inside of the method will change its value, EDIT: Ok after doing some googleing I see ByRef isnt possible in Java.. What a shame. Another solution would be to create your own class and have the loopCount as a property, since all objects in java are passed by reference.
the method with a variable such as Int loopCount 0; Function ThisIsYourFunction(ByRef loopCount) Do Some loops loopCount++ SomeOtherMathHere Return yourReturnValue Since loopCount was passed by reference anything you do to it inside of the method will change its value, EDIT: Ok after doing some googleing I see ByRef isnt possible in Java.. What a shame. Another solution would be to create your own class and have the loopCount as a property, since all objects in java are passed by reference.
Mon, 06 Feb 2012 09:50:44 GMT
I'm no java expert, in fact, as I was typing java I impulsively typed script after return an array with steps first, answer second or return an object with obj.steps and obj.result
Mon, 06 Feb 2012 09:59:14 GMT
Method#1: /** Use an array to return two value */ public int[] methodReturningTwoInts() int a getA(); int b getB(); return new int[] a, b } Method#2: /** Use a Map to return two value */ public Map methodReturningTwoInts() int a getA(); int b getB(); Map result new HashMap(); result.put("a", a); result.put("b", b); return result; Method#3: /** Use a object to return two values */ public MyBean methodReturningTwoValues() int a getA(); String b getB(); return new MyBean(a, b); Method#4: Make both result and loop variable class level variables.
use Object.YourSqrtMethod() to calculate and YourObject.ShowResult() to display results etc Method#55 Send i and r variables as reference/pointer to YourSqrtMethod. In YourSqrtMethod at end set their (i and r) values and return.
will then display them.
use Object.YourSqrtMethod() to calculate and YourObject.ShowResult() to display results etc Method#55 Send i and r variables as reference/pointer to YourSqrtMethod. In YourSqrtMethod at end set their (i and r) values and return.
will then display them.
Mon, 06 Feb 2012 11:03:13 GMT