-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab3_2.java
More file actions
74 lines (64 loc) · 2.7 KB
/
Lab3_2.java
File metadata and controls
74 lines (64 loc) · 2.7 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.ArrayList;
import java.util.Scanner;
public class Lab3_2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
try {
while (true) {
/* ИНИЦИАЛИЗАЦИЯ И ВВОД МАССИВА */
System.out.println("Для выхода из программы введите любой не числовой символ/последовательность символов");
System.out.println("Введите размерность массива m на n: ");
System.out.print("m= ");
int row_count = scanner.nextInt();
System.out.print("n= ");
int column_count = scanner.nextInt();
int[][] array = create_array(row_count, column_count);
output_array(array, row_count, column_count);
System.out.println("Введите начало и конец отрезка");
System.out.print("a= ");
int a = scanner.nextInt();
System.out.print("b= ");
int b = scanner.nextInt();
ArrayList<Integer> total_array = new ArrayList<Integer>();
for (int i=0; i < column_count; i++){
int sum = 0;
for (int j = 0; j< row_count; j++){
if (!check_entry_into_segment(a, b, array[i][j])){
sum+=array[i][j];
}
}
total_array.add(sum);
}
for (int i = 0; i < total_array.size(); i++) {
System.out.print(total_array.get(i) + " ");
}
}
} catch (Throwable t) {
System.out.println("Вы вышли из программы");
}
}
private static void output_array(int[][] array, int row_count, int column_count){
for (int i = 0; i < row_count; i++) {
for (int j = 0; j < column_count; j++) {
System.out.print(" " + array[i][j] + " ");
}
System.out.println("");
}
}
private static int [][] create_array(int row_count, int column_count){
int array[][] = new int[row_count][column_count];
for (int i = 0; i < row_count; i++) {
for (int j = 0; j < column_count; j++) {
array[i][j] = ((int) (Math.random() * 101) - 50);
}
}
return array;
}
private static boolean check_entry_into_segment(int a, int b, int num){
if (num >= a && num <= b){
return true;
} else {
return false;
}
}
}