Advertisement
Guest User

Untitled

a guest
Feb 15th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public class dz {
  2. public static void main(String[] args) {
  3. int[] numArray = new int[]{4,-2,1,7,2,5,-4};
  4.  
  5. int summa = 0;
  6. for (int i = 0; i < numArray.length; i+=2) {
  7. summa += numArray[i];}
  8.  
  9. System.out.print(" сумма элементов с четными индексами: " + summa );
  10.  
  11. System.out.println( " ");
  12.  
  13. int pro = 1;
  14. for(int i = 1; i< numArray.length; i+=2) {
  15. pro *= numArray[i];}
  16. System.out.print(" произведение элементов с нечетными индексами: " + pro );
  17.  
  18. System.out.println( " ");
  19. int sum = 0;
  20. for (int i = 0; i < numArray.length; i++) {
  21. if (numArray[i] < 0) {
  22. sum += numArray[i];
  23. System.out.println(" сумма отрицательных элементов массива: " + sum);
  24. System.out.println( " ");
  25.  
  26. for (int i = 0; i < numArray.length; i++) {
  27. if (numArray[i] % 5 == 0) {
  28. System.out.print( " элементы делящиеся на 5 " + numArray[i]);}
  29.  
  30. for (int i = 0; i < numArray.length; i++) {
  31. if (i == 0) {
  32. System.out.print( " индекс элементов равных нулю " + numArray[i]);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement