-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask6.java
More file actions
53 lines (51 loc) · 1.64 KB
/
Copy pathtask6.java
File metadata and controls
53 lines (51 loc) · 1.64 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
43
44
45
46
47
48
49
50
51
52
53
package array_tasks;
//task 6 from Pavlovskaya C#
public class task6 {
public static void main(String[] args) {
int size = 5, cnt = 0, index = 0, rezI = 0, indexRow = 0;
int[][] matrix = {{0,4,5,7,5}, {1,0,3,3,3}, {5,0,0,5,6}, {6,7,4,2,1}, {5,6,3,2,2,1}};
System.out.println("Source matrix: ");
print(matrix, size);
System.out.print("Count of column with zeros: ");
System.out.print(countOfColumnWithZeros(matrix, size));
for (int i = 0; i < matrix.length; ++i){
index = numOfString(matrix[i]);
if (index > rezI) {
rezI = index;
indexRow = i;
}
}
System.out.println("\r\nLine " + indexRow + " series of " + (rezI + 1) + " identical numbers.");
}
static int countOfColumnWithZeros(int[][] matrix, int size){
int cnt = 0;
for (int i = 0; i < size; ++i){
for (int j = 0; j < size; ++j)
if (matrix[i][j] == 0) {
cnt++;
break;
}
}
return (cnt);
}
static int numOfString(int[] tmp){
int ecx = 0, t = tmp[0], cnt = 0;
for (int i = 1; i < tmp.length; ++i) {
if (tmp[i] == t)
cnt++;
else
cnt = 0;
t = tmp[i];
if (cnt > ecx)
ecx = cnt;
}
return (ecx);
}
static void print(int[][] matrix, int size){
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size; ++j)
System.out.print(" " + matrix[i][j]);
System.out.println();
}
}
}