lr13 -> task_2 -> e1-e3
This commit is contained in:
41
lr13/task_2/e2.java
Normal file
41
lr13/task_2/e2.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package lr13.task_2;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class e2 {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
try {
|
||||
System.out.print("Введите строки и столбцы: ");
|
||||
int n = sc.nextInt();
|
||||
int m = sc.nextInt();
|
||||
|
||||
int[][] a = new int[n][m];
|
||||
|
||||
System.out.println("Введите матрицу:");
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
a[i][j] = sc.nextInt();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.print("Введите номер столбца: ");
|
||||
int col = sc.nextInt();
|
||||
|
||||
System.out.println("Столбец:");
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
System.out.println(a[i][col]);
|
||||
}
|
||||
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Ошибка: введена строка вместо числа");
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
System.out.println("Ошибка: нет такого столбца");
|
||||
} finally {
|
||||
System.out.println("Работа завершена");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user