Advertisement
apez1

Term 1: Lesson 34 - Coding Activity 2

Nov 28th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.math.*;
  3.  
  4. public class Lesson_34_Activity_Two {
  5.    
  6.     static Scanner scanner = new Scanner(System.in);
  7.    
  8.     public static double average(int a[]) {
  9.    
  10.     double before = 0;
  11.     double avg = 0 ;   
  12.        
  13.         for(int i =0; i <a.length;i++) {
  14.             before = before + a[i];
  15.         }
  16.        
  17.        
  18.         avg = (1.0)*(before / a.length);
  19.        
  20.         return avg;
  21.     }
  22.  
  23.    
  24.  
  25.     public static void main(String[] args) {   
  26.    
  27.     int a[] = {1,2,3};
  28.    
  29.  
  30.     double  x = average(a);
  31.    
  32.    System.out.println(x);
  33.    
  34.     }
  35.    
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement