Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyClass {
- public static void main(String args[]) {
- int[] example = {-1, -2, -3, -4};
- System.out.println(sumNegative(example));
- }
- //сумма отрицательных элементов
- public static int sumNegative(int[] array){
- int summ = 0;
- for(int i = 0; i < array.length; i++){
- if(array[i] < 0) summ += array[i];
- }
- return summ;
- }
- }
Add Comment
Please, Sign In to add comment