This repository was archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaba4.java
More file actions
142 lines (133 loc) · 4.32 KB
/
Copy pathLaba4.java
File metadata and controls
142 lines (133 loc) · 4.32 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package com.company;
import java.util.Random;
import java.util.Scanner;
import java.util.Vector;
public class Main {
static void InputArr(int[][] arr,int n,int m)
{
for(int i=0;i<n;i++)
{
System.out.println("Рядок№ "+ (i+1));
for(int j=0;j<m;j++) {
arr[i][j] = new Scanner(System.in).nextInt();
}
}
}
static void Task1(Scanner num) {
byte n;
byte m;
boolean a;
do {
System.out.println("Висота матриці: ");
n = new Scanner(System.in).nextByte();
System.out.println("Ширина матриці: ");
m = new Scanner(System.in).nextByte();
a =false;
if(n<=0||m<=0)
{
System.out.println("Некоректне введення!!");
a=true;
}
}while(a!=false);
int[][]A =new int[n][m];
InputArr(A,n,m);
System.out.println("Рядки з нульовими елементами: ");
boolean key=true;
for(int i=0;i<n;i++)
{
for (int j = 0;j < m; j++)
{
if (A[i][j] == 0)
{
key=false;
System.out.println("\nНомер рядка: ");
System.out.println(i);
System.out.println("Рядок: ");
for(int k=0;k<m;k++)
{
System.out.print(A[i][k]+" ");
}
break;
}
}
}
if(key)
{
System.out.println("Відсутні!");
}
}
static void Task2(Scanner num)
{
Random rnd = new Random(System.currentTimeMillis());
int min = -100;
int max = 100;
System.out.println("Введіть розмір квадратної матриці(>0):");
int size= num.nextByte();
while(size<0||size==0)
{
System.out.println("недопустиме значення...Введіть щераз: ");
size= num.nextByte();
}
int[][] A=new int[size][size];
System.out.println("Заповнення матриці випадковими числами.....");
for(int i=0;i<size;i++)
for (int j=0;j<size;j++)
A[i][j] = min + rnd.nextInt(max - min + 1);
System.out.println("Вивід матриці: ");
for(int i=0;i<size;i++)
{
for (int j = 0; j < size; j++)
System.out.print("\t\t"+A[i][j]);
System.out.println("\n");
}
System.out.println("Введіть першу межу інтервалу: ");
int a=num.nextInt();
System.out.println("Введіть другу межу інтервалу: ");
int b=num.nextInt();
while(b<=a)
{
System.out.println("Введіть щераз(b<=a)");
b=num.nextInt();
}
Vector<Integer> v=new Vector<Integer>();
for(int i=0;i<size;i++)
{
for (int j = 0; j < size; j++)
{
if(A[i][j]>=a&&A[i][j]<=b)
v.add(A[i][j]);
}
}
System.out.println("Вивід елементів які добвленні в вектор на проміжку:");
for (Integer i:v)
{
System.out.print(i+" ");
}
}
public static void main(String[] args) {
boolean run=true;
byte number;
Scanner num=new Scanner(System.in);
while(run) {
System.out.println("\nВибертіть номер завдання (1-2, 5-ВИХІД!): ");
number = num.nextByte();
switch (number) {
case 1:
System.out.println("Завдання 1: ");
Task1(num);
break;
case 2:
Task2(num);
break;
case 5:
System.out.println("Завершення виконання....");
run=false;
break;
default:
System.out.println("Введіть щераз: ");
number=num.nextByte();
break;
}
}
}
}