Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Emelda Fonki
30 Pointsi need help with this code
Statistics are often calculated varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outputs the average and max. A negative integer ends the input and is not included in the statistics. When the input is 15 20 0 5 -1, the output is 10 20. You can assume that at least one non-negative integer is input.
Emelda Fonki
30 PointsStatistics are often calculated varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outputs the average and max. A negative integer ends the input and is not included in the statistics. When the input is 15 20 0 5 -1, the output is 10 20. You can assume that at least one non-negative integer is input.
Joseph Wasden
20,407 PointsI see...
So, this is a textbook (or otherwise) problem from outside of Treehouse, and you're looking for some kind of assistance in writing the program?
1 Answer
Joseph Wasden
20,407 PointsThis should get you going. This only provides the average; you'll need to reason out how to get the max value.
public static double getAverage(int[] array)
{
int sum = 0;
for(int i : array) sum += i;
return ((double) sum)/array.length;
}
Joseph Wasden
20,407 PointsJoseph Wasden
20,407 PointsPlease provide the code and/or a link to the video in question.