Advertisement
apez1

Term 1: Lesson 34 - Coding Activity 1

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