project_number_03

sumNegative

Jan 11th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         int[] example = {-1, -2, -3, -4};
  4.         System.out.println(sumNegative(example));
  5.     }
  6.    
  7. //сумма отрицательных элементов
  8.     public static int sumNegative(int[] array){
  9.         int summ = 0;
  10.         for(int i = 0; i < array.length; i++){
  11.             if(array[i] < 0) summ += array[i];
  12.         }
  13.         return summ;
  14.     }
  15. }
Add Comment
Please, Sign In to add comment