java return multiple values code example

Example 1: c++ return multiple values

#include <tuple>

std::tuple<int, int> divide(int dividend, int divisor) {
    return  std::make_tuple(dividend / divisor, dividend % divisor);
}

#include <iostream>

int main() {
    using namespace std;

    int quotient, remainder;

    tie(quotient, remainder) = divide(14, 3);

    cout << quotient << ',' << remainder << endl;
}

Example 2: how to return two values from a function in java

int[] ans = new int[2];
        ans[0] = a + b;
        ans[1] = a - b;

return ans;

Tags:

Java Example