Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class dz {
- public static void main(String[] args) {
- int[] numArray = new int[]{4,-2,1,7,2,5,-4};
- int summa = 0;
- for (int i = 0; i < numArray.length; i+=2) {
- summa += numArray[i];}
- System.out.print(" сумма элементов с четными индексами: " + summa );
- System.out.println( " ");
- int pro = 1;
- for(int i = 1; i< numArray.length; i+=2) {
- pro *= numArray[i];}
- System.out.print(" произведение элементов с нечетными индексами: " + pro );
- System.out.println( " ");
- int sum = 0;
- for (int i = 0; i < numArray.length; i++) {
- if (numArray[i] < 0) {
- sum += numArray[i];
- System.out.println(" сумма отрицательных элементов массива: " + sum);
- System.out.println( " ");
- for (int i = 0; i < numArray.length; i++) {
- if (numArray[i] % 5 == 0) {
- System.out.print( " элементы делящиеся на 5 " + numArray[i]);}
- for (int i = 0; i < numArray.length; i++) {
- if (i == 0) {
- System.out.print( " индекс элементов равных нулю " + numArray[i]);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement