This repository was archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask5.java
More file actions
42 lines (42 loc) · 2.29 KB
/
task5.java
File metadata and controls
42 lines (42 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package uits.jv1605.dmitriev.basictypes.hw2;
public class task5 {
public static void arrays2D(int m, int n){
int array2D[][]=new int[m][n];
for (int i=0; i<array2D.length;i++){
for (int j=0; j<array2D.length; j++){
array2D[i][j]=(int)(Math.random()*100);}}
System.out.println("Массив задания 5 в прямом порядке");
for (int i=0; i<array2D.length;i++){
System.out.println(java.util.Arrays.toString(array2D[i]));}
System.out.println("Массив задания 5 в обратном порядке");
for (int i=0; i<array2D.length;i++){ // Инверсия массива
for (int k=0; k<array2D.length/2;k++){
int tmp=array2D[i][k];
array2D[i][k]=array2D[i][array2D.length-k-1];
array2D[i][array2D.length-k-1]=tmp;}}
for (int i=0; i<array2D.length;i++){
System.out.println(java.util.Arrays.toString(array2D[i]));}
// Выводим четные элементы для каждой четной строки
for (int i=0; i<array2D.length; i++){
for (int j=0; j<array2D.length; j++){
if (i%2==0){ if(array2D[i][j]%2==0){System.out.print(array2D[i][j]+ " ");}} }
} System.out.println();
// Выводим нечетные элементы для каждой нечетной строки
for (int i=0; i<array2D.length; i++){
for (int j=0; j<array2D.length; j++){
if (i%2!=0){ if(array2D[i][j]%2!=0){System.out.print(array2D[i][j]+ " ");}} }}
System.out.println();
// Выводим сумму всех элементов, кратных 7
int sum72D=0;
for (int i=0; i<array2D.length; i++){
for (int j=0; j<array2D.length; j++){
if (i%2==0){ if(array2D[i][j]%7==0){sum72D+=array2D[i][j];}} }
} System.out.println("Сумма всех элементов, кратных 7, в четных строках = " + sum72D);
// Выводим произведение элементов, кратных 3 в нечетных строках
int pr32D=1;
for (int i=0; i<array2D.length; i++){
for (int j=0; j<array2D.length; j++){
if (i%2!=0){ if(array2D[i][j]%3==0){pr32D*=array2D[i][j];}} }
} System.out.println("Произведение всех элементов, кратных 3, в нечетных строках = " + pr32D);
}
}