SHARE
TWEET

sumNegative

project_number_03 Jan 11th, 2019 (edited) 18 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top