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(

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: