devxlogo

Returning Multiple Values From A Method

Returning Multiple Values From A Method

Suppose you have some C++ code that you’d like to convert to the Java programming language. While doing the conversion, you come across the following code:

 void getStats(int data[], int& count,  int& sum, int& mean) {    count = 0;    sum = 0;    mean =  0;    for (int i = 0; data[i] != -1; i++) {      count++;      sum += data[i];    }    if (count < 0) {      mean = sum / count;    }  }  int main() {    int data[] = {10, 17, 39, -1};    int count;    int sum;    int mean;    getStats(data, count, sum, mean);    printf(

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist