Skip to content

Instantly share code, notes, and snippets.

@LordNairu
Created November 17, 2013 23:32
Show Gist options
  • Save LordNairu/7519797 to your computer and use it in GitHub Desktop.
Save LordNairu/7519797 to your computer and use it in GitHub Desktop.
package qub.ac.uk.practical.week5;
public class PracticalFiveQuestionTwo {
public static void main(String[] args) {
// Declaring vars
double average;
average = 0.0;
// Populating array with temps
double [] tempArray = { 3.4, 4.2, 9.0, 2.2, 4.5, 6.4, 3.1 };
// Foreach on Array to calculate average
for (double avgTemp : tempArray)
{
average += avgTemp/tempArray.length;
}
// Printing average
System.out.println(Math.round(average*100.0)/100.0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment