• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

returning values

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have it so it will return 1 value, but if i need to take it more than one value in my class how would i do it?

The example here should take the grades of 4 students, to find the average but i don't know how to take it more than one, here's some code.



this is link to a file called marks, where the grades of four students are entered using an array.

Cheers.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not clear about your question.

If you are asking if you can return more than one value from a method, you can't.

If you want multiple values from a method, you should encapsulate them in a class definition and return an instance of that class.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your English is difficult to understand (perhaps you could get someone who speaks better English to write your post) but I think you are asking how to find the average grade of a group of students. An instance of StudentV2 represents *one* student, so I don't think it makes sense for such an object to know the average of four students. You could define a class, say StudentCohort, that holds a collection of students. If you ask a cohort for its average, it will find that out by asking each individual for its grade, then doing the math.
 
There is no "i" in denial. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic