Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- int m = 0;
- int n = 0;
- System.out.println("Введите количество строк:");
- m = EnterValue();
- System.out.println("Введите количество столбов:");
- n = EnterValue();
- int[][] array = new int[n][m];
- for(int x = 0; x < n; x++){
- for(int i = 0; i < m; i++){
- System.out.println("Введите значение для array["+x+"]["+i+"]");
- Scanner entervalue = new Scanner(System.in);
- while(true){
- try{
- array[x][i] = entervalue.nextInt();
- break;
- }catch (java.util.InputMismatchException e){
- System.out.println("Введите число!");
- continue;
- }
- }
- }
- }
- int maximum_value;
- maximum_value = FindMax(array);
- System.out.println("Самое большое число в массиве: "+maximum_value);
- }
- public static int FindMax(int arr[][]){
- int max = 0;
- for(int x = 0; x < arr[0].length; x++){
- for(int i = 0; i < arr[1].length; i++){
- if(max < arr[x][i]) max = arr[x][i];
- }
- }
- return max;
- }
- public static int EnterValue(){
- int value = 0;
- while(value == 0) {
- try {
- Scanner scan_arrays = new Scanner(System.in);
- int exec = scan_arrays.nextInt();
- if(exec < 2){
- System.out.println("Число от 2 до 10");
- continue;
- }
- value = exec;
- break;
- } catch (java.util.InputMismatchException e) {
- System.out.println("Введите целочисленное значение!");
- value = 0;
- }
- }
- return value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement