Calculating an average with an array in Java; Homework -


i have homework assignment, , these 5 questions,

  1. what total of elements in array.
  2. what average of elements in array.
  3. what largest , smallest numbers in array. (one loop both questions)
  4. display odd numbers in array. use modulus function (%) on page 46.
  5. print every other number in array.

i having trouble finding average, or writing code finds it.

public class javaapplication {      /**      * @param args command line arguments      */     public static void main(string[] args) {         // todo code application logic here         int nums[] = {33,66,77,88,60,91,87,92,76,90};         int sum = 0;         (int = 0; < 10; i++){             sum +=nums[i];          }             system.out.println("the sum " + sum);          int average = 0;                         here         (int = 0; < nums.length; i++) {  |             sum = sum + nums[i];                 |         }         system.out.println("average value " + average); , here.           int min, max;                                                 min = max = nums [0];         for(int i=1; < 10; i++) {             if(nums[i] < min) min = nums[i];             if(nums[i] > max) max = nums[i];         }         system.out.println("min , max: " + min + " " + max);       } } 

this second week in class, please explain needs added or not , :)

the pseudo code average n elements :

1) add of element values 2) divide result step 1 number of elements in collection 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -