deyanmalinov

02. Matrix of Palindromes

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