-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayTest.java
More file actions
33 lines (30 loc) · 1.41 KB
/
ArrayTest.java
File metadata and controls
33 lines (30 loc) · 1.41 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
package GeekBrains;
import java.io.IOException;
import java.util.Arrays;
public class ArrayTest {
public void arrMh(String[][] array) throws MyArraySizeException,MyArrayDataException {
if (array.length==4 && array[0].length==4 && array[1].length==4 && array[2].length==4 && array[3].length==4){ // проверка размера массива
int s = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
try {
s += (Integer.parseInt(array[i][j]));
} catch (NumberFormatException e) {
// e.printStackTrace();
throw new MyArrayDataException("преобразование не удалось: в ячейке массива "
+"["+i+"]"+"["+j+"]"+" записано " +array[i][j]);
}
}
}
System.out.println(Arrays.deepToString(array));
System.out.println("Сумма массива: "+s);}
else {
try {
throw new MyArraySizeException("Задан массив неверного размера");
}catch (MyArraySizeException e){
e.printStackTrace();
System.out.println("Задайте новый массив");
}
}
}
}