42 lines
1.2 KiB
Java
42 lines
1.2 KiB
Java
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("Работа завершена");
|
|
}
|
|
}
|
|
}
|