Advertisement
Ligh7_of_H3av3n

02. Matrix of Palindromes

May 17th, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package Uprajnenie;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class MatrixOfPalindromes {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.  
  12.         // Read input
  13.         String[] dimensions = scanner.nextLine().split(" ");
  14.         int matrixRow = Integer.parseInt(dimensions[0]);
  15.         int matrixCol = Integer.parseInt(dimensions[1]);
  16.  
  17.         // Create and fill the matrix
  18.         String[][] matrix = new String[matrixRow][matrixCol];
  19.         for (int row = 0; row < matrixRow; row++) {
  20.             for (int col = 0; col < matrixCol; col++) {
  21.                 char first = (char) ('a' + row);
  22.                 char middle = (char) ('a' + row + col);
  23.                 char last = (char) ('a' + row);
  24.                 matrix[row][col] = "" + first + middle + last;
  25.             }
  26.         }
  27.  
  28.         // Print the matrix
  29.         for (int row = 0; row < matrixRow; row++) {
  30.             for (int col = 0; col < matrixCol; col++) {
  31.                 System.out.print(matrix[row][col] + " ");
  32.             }
  33.             System.out.println();
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement