A scientist measures outdoor temperature 5 times a week.
He is writing a program to process the data a determine the
A random number generator is used to simulate temperatures.
| 0 | 1 | 2 | 3 | 4 |
Start a new project in your IDE called ArraysIntro.
Paste the starter code and open the worksheet.
Note: if you are struggling with this unit, the helper video covers the concepts in the worksheet.
So each element in an array has an index, starting at 0.
We can use this
int[ ] nums = {13,16,34,65,34,76}; //this is a shortcut to initialising an array!
int total = 0;
for(int i = 0; i< nums.length; i++){ //nums.length is handy!
total = total + nums[i];
}
System.out.println("The total is "+total);
Design a function countTemp(int threshold) which returns a count of all values in the global array referenced by nums which are less than our equal to the parameter threshold.
Design a function getTotal() which returns the sum of all values in the global array referenced by nums.
Design a function getAveragel() which returns the average of all values in the global array referenced by nums.
Your solution must call the getTotal function to help solve this problem.
If you get it, let's continue to the exercises.
iterateauto-indent variablecompile sum machine code count-controlled loop integer pseudocodesyntax