mengembalikan dua nilai di java
// A Java program to demonstrate that a method
// can return multiple values of same type by
// returning an array
class Test {
// Returns an array such that first element
// of array is a+b, and second element is a-b
static int[] getSumAndSub(int a, int b)
{
int[] ans = new int[2];
ans[0] = a + b;
ans[1] = a - b;
// returning array of elements
return ans;
}
// Driver method
public static void main(String[] args)
{
int[] ans = getSumAndSub(100, 50);
System.out.println("Sum = " + ans[0]);
System.out.println("Sub = " + ans[1]);
}
}
Bad Batfish