Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java, C++
Expertise: Intermediate
Jul 19, 2001

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(
Sudip Bhattacharya
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date