কম্পিউটার

একটি ম্যাট্রিক্সের সীমানা উপাদান প্রিন্ট করার জন্য জাভা প্রোগ্রাম


এই নিবন্ধে, আমরা বুঝব কিভাবে একটি ম্যাট্রিক্সের সীমানা উপাদান প্রিন্ট করতে হয়। একটি ম্যাট্রিক্স হল সারি এবং কলামের উপাদানগুলির প্রতিনিধিত্ব। সীমানা উপাদান হল সেই সকল উপাদান যা চার দিকের উপাদান দ্বারা বেষ্টিত নয়। উদাহরণস্বরূপ, প্রথম সারি, প্রথম কলাম, শেষ সারি এবং শেষ কলামের উপাদান৷

নীচে একই -

এর একটি প্রদর্শন রয়েছে৷

ধরুন আমাদের ইনপুট হল

The input matrix:
9 8 9 8
8 7 8 7
7 6 7 6
6 5 6 5

কাঙ্খিত আউটপুট হবে

The border elements of the matrix is:
9 8 9 8
8     7
7     6
6 5 6 5

অ্যালগরিদম

Step 1 - START
Step 2 - Declare an integer matrix namely input_matrix, an object of the class BoundaryElements namely border_values.
Step 3 - Define the values.
Step 4 - Iterate over each element of the matrix using two for-loops and check if the element is a boundary element using Boolean OR condition.
Step 5 - Display the boundary elements.
Step 5 - Stop

উদাহরণ 1

এখানে, একটি প্রম্পটের উপর ভিত্তি করে ব্যবহারকারী দ্বারা ইনপুট প্রবেশ করানো হচ্ছে।

public class BoundaryElements {
   public static void main(String[] args) {
      int input_matrix[][] = new int[][] {
         { 9, 8, 9, 8 },
         { 8, 7, 8, 7 },
         { 7, 6, 7, 6 },
         { 6, 5, 6, 5 }
      };
      System.out.println("The matrix is defined as: ");
      for (int x = 0; x < input_matrix.length; x++) {
         for (int y = 0; y < input_matrix[x].length; y++) {
            System.out.print(input_matrix[x][y] + " ");
         }
         System.out.println();
      }
      BoundaryElements border_values = new BoundaryElements();
      System.out.println("The border elements of the matrix is:");
      for (int x = 0; x < input_matrix.length; x++) {
         for (int y = 0; y < input_matrix[x].length; y++) {
            if (x == 0 || y == 0 || x == input_matrix.length - 1
               || y == input_matrix[x].length - 1) {
               System.out.print(input_matrix[x][y] + " ");
            } else {
               System.out.print(" ");
            }
         }
         System.out.println();
      }
   }
}

আউটপুট

The matrix is defined as:
9 8 9 8
8 7 8 7
7 6 7 6
6 5 6 5
The border elements of the matrix is:
9 8 9 8
8 7
7 6
6 5 6 5

উদাহরণ 2

এখানে, পূর্ণসংখ্যা পূর্বে সংজ্ঞায়িত করা হয়েছে, এবং এর মান অ্যাক্সেস করা হয়েছে এবং কনসোলে প্রদর্শিত হয়েছে।

public class BoundryElements {
   public void Boundary_Elements(int input_matrix[][]) {
      System.out.println("The matrix is defined as: ");
      for (int x = 0; x < input_matrix.length; x++) {
         for (int y = 0; y < input_matrix[x].length; y++) {
            System.out.print(input_matrix[x][y] + " ");
         }
         System.out.println();
      }
      System.out.println("The border elements of the matrix is:");
      for (int x = 0; x < input_matrix.length; x++) {
         for (int y = 0; y < input_matrix[x].length; y++) {
            if (x == 0 || y == 0 || x == input_matrix.length - 1
               || y == input_matrix[x].length - 1) {
               System.out.print(input_matrix[x][y] + " ");
            } else {
               System.out.print(" ");
            }
         }
         System.out.println();
      }
   }
   public static void main(String[] args) {
      int input_matrix[][] = new int[][] {
         { 9, 8, 9, 8 },
         { 8, 7, 8, 7 },
         { 7, 6, 7, 6 },
         { 6, 5, 6, 5 }
      };
      BoundryElements border_values = new BoundryElements();
      border_values.Boundary_Elements(input_matrix);
   }
}

আউটপুট

The matrix is defined as:
9 8 9 8
8 7 8 7
7 6 7 6
6 5 6 5
The border elements of the matrix is:
9 8 9 8
8 7
7 6
6 5 6 5

  1. জাভা প্রোগ্রাম Z আকারে ম্যাট্রিক্স প্রিন্ট করতে

  2. একটি আইডেন্টিটি ম্যাট্রিক্স প্রিন্ট করার জন্য পাইথন প্রোগ্রাম

  3. পাইথনে সর্পিল ক্রমে ম্যাট্রিক্স উপাদান প্রিন্ট করার জন্য প্রোগ্রাম

  4. Z আকারে ম্যাট্রিক্স প্রিন্ট করার জন্য পাইথন প্রোগ্রাম