Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Main {
- public static void main(String[] args) {
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- try {
- System.out.print("No. of rows: ");
- int m = Integer.parseInt(br.readLine());
- System.out.print("No. of columns: ");
- int n = Integer.parseInt(br.readLine());
- int A[][] = new int[m][n];
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- System.out.print("Enter the elements: ");
- A[i][j] = Integer.parseInt(br.readLine());
- }
- }
- System.out.println("The original array:");
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- System.out.print(A[i][j] + "\t");
- }
- System.out.println();
- }
- int t = 0;
- for (int x = 0; x < m; x++) {
- for (int y = 0; y < n; y++) {
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- if (A[i][j] > A[x][y]) {
- t = A[x][y];
- A[x][y] = A[i][j];
- A[i][j] = t;
- }
- }
- }
- }
- }
- System.out.println("The Sorted Array:");
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- System.out.print(A[i][j] + "\t");
- }
- System.out.println();
- }
- }catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment