Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         int m = 0;
  6.         int n = 0;
  7.  
  8.         System.out.println("Введите количество строк:");
  9.         m = EnterValue();
  10.         System.out.println("Введите количество столбов:");
  11.         n = EnterValue();
  12.  
  13.         int[][] array = new int[n][m];
  14.  
  15.         for(int x = 0; x < n; x++){
  16.             for(int i = 0; i < m; i++){
  17.                 System.out.println("Введите значение для array["+x+"]["+i+"]");
  18.  
  19.                 Scanner entervalue = new Scanner(System.in);
  20.                 while(true){
  21.                     try{
  22.                         array[x][i] = entervalue.nextInt();
  23.                         break;
  24.                     }catch (java.util.InputMismatchException e){
  25.                         System.out.println("Введите число!");
  26.                         continue;
  27.                     }
  28.                 }
  29.             }
  30.         }
  31.         int maximum_value;
  32.         maximum_value = FindMax(array);
  33.         System.out.println("Самое большое число в массиве: "+maximum_value);
  34.     }
  35.     public static int FindMax(int arr[][]){
  36.         int max = 0;
  37.         for(int x = 0; x < arr[0].length; x++){
  38.             for(int i = 0; i < arr[1].length; i++){
  39.                 if(max < arr[x][i]) max = arr[x][i];
  40.             }
  41.         }
  42.         return max;
  43.     }
  44.     public static int EnterValue(){
  45.         int value = 0;
  46.         while(value == 0) {
  47.             try {
  48.                 Scanner scan_arrays = new Scanner(System.in);
  49.                 int exec = scan_arrays.nextInt();
  50.  
  51.                 if(exec < 2){
  52.                     System.out.println("Число от 2 до 10");
  53.                     continue;
  54.                 }
  55.                 value = exec;
  56.                 break;
  57.             } catch (java.util.InputMismatchException e) {
  58.                 System.out.println("Введите целочисленное значение!");
  59.                 value = 0;
  60.             }
  61.         }
  62.         return value;
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement