Advertisement
ABaDy1996

TT

Nov 24th, 2020
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class array2 {
  4.     public static void main(String[] args) {
  5.         int[][] a = new int[5][2];
  6.         fil(a);
  7.         System.out.print("befoe");
  8.         print(a);
  9.         int max = 0;
  10.         max(a);
  11.         System.out.print("the max is " + max);
  12.         re(a);
  13.         System.out.println("after");
  14.         print(a);
  15.     }
  16.  
  17.     public static void fil(int[][] a) {
  18.         Scanner in = new Scanner(System.in);
  19.         for (int r = 0; r < a.length; r++) {
  20.             for (int c = 0; c < a[r].length; c++) {
  21.                 System.out.println("Enter data to row " + (r + 1) + " and clome " + (c + 1));
  22.                 a[r][c] = in.nextInt();
  23.             }
  24.         }
  25.  
  26.     }
  27.  
  28.     public static void max(int[][] m) {
  29.         int max = 0;
  30.         for (int r = 0; r < m.length; r++) {
  31.             for (int c = 0; c < m[r].length; c++) {
  32.                 if (m[r][c] > max)
  33.                     max = m[r][c];
  34.  
  35.             }
  36.         }
  37.  
  38.     }
  39.  
  40.     public static void print(int[][] a) {
  41.         for (int r = 0; r < a.length; r++) {
  42.             for (int c = 0; c < a[r].length; c++) {
  43.                 System.out.print(a[r][c] + "  ");
  44.  
  45.             }
  46.             System.out.println();
  47.         }
  48.     }
  49.  
  50.     public static void re(int[][] t) {
  51.  
  52.         int temp = 0;
  53.         for (int r = 0; r < t.length-1; r++) {
  54.             for (int c = 0; c < t[r].length-1; c++) {
  55.                 temp = t[0][0];
  56.                 t[r][c] = t[r + 1][c + 1];
  57.                 t[t.length - 1][t[r].length - 1] = temp;
  58.             }
  59.         }
  60.  
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement