Didart

Matrix of Palindromes

Jan 14th, 2023
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package MultidimensionalArrays2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class MatrixOfPalindromes {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String[] line = scanner.nextLine().split(" ");
  10.         int rows = Integer.parseInt(line[0]);
  11.         int cols = Integer.parseInt(line[1]);
  12.  
  13.         String[][] matrix = new String[rows][cols];
  14.  
  15.         for (int row = 0; row < matrix.length; row++) {
  16.             for (int col = 0; col < matrix[0].length; col++) {
  17.                 String symbol ="" + (char)('a'+ row) + (char)('a'+ row + col) + (char)('a'+ row);
  18.                 matrix[row][col] = symbol;
  19.             }
  20.         }
  21.         for (int row = 0; row < matrix.length; row++) {
  22.             for (int col = 0; col < matrix[row].length; col++) {
  23.                 System.out.print(matrix[row][col]+ " ");
  24.  
  25.             }
  26.             System.out.println();
  27.         }
  28.     }
  29. }
  30.  
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment