chillurbrain

10. Абсолютная сортировка

May 21st, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1.  
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  10.     try {
  11.         System.out.print("No. of  rows: ");
  12.         int m = Integer.parseInt(br.readLine());
  13.         System.out.print("No. of columns: ");
  14.         int n = Integer.parseInt(br.readLine());
  15.  
  16.         int A[][] = new int[m][n];
  17.  
  18.            
  19.  
  20.         for (int i = 0; i < m; i++) {
  21.             for (int j = 0; j < n; j++) {
  22.                 System.out.print("Enter the elements: ");
  23.                 A[i][j] = Integer.parseInt(br.readLine());
  24.             }
  25.         }
  26.  
  27.         System.out.println("The original array:");
  28.         for (int i = 0; i < m; i++) {
  29.             for (int j = 0; j < n; j++) {
  30.                 System.out.print(A[i][j] + "\t");
  31.             }
  32.             System.out.println();
  33.         }
  34.  
  35.         int t = 0;
  36.         for (int x = 0; x < m; x++) {
  37.             for (int y = 0; y < n; y++) {
  38.                 for (int i = 0; i < m; i++) {
  39.                     for (int j = 0; j < n; j++) {
  40.                         if (A[i][j] > A[x][y]) {
  41.                             t = A[x][y];
  42.                             A[x][y] = A[i][j];
  43.                             A[i][j] = t;
  44.                         }
  45.                     }
  46.                 }
  47.             }
  48.         }
  49.  
  50.         System.out.println("The Sorted Array:");
  51.         for (int i = 0; i < m; i++) {
  52.             for (int j = 0; j < n; j++) {
  53.                 System.out.print(A[i][j] + "\t");
  54.             }
  55.             System.out.println();
  56.         }
  57.     }catch (IOException e) {
  58.         e.printStackTrace();
  59.     }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment