Advertisement
Five_NT

lab1

Feb 22nd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. /**
  2.  * Created by satellite on 21.02.2017.
  3.  */
  4. public class latinSquare {
  5.     public static void main(String[] args) {
  6.         int dim = 4;
  7.         String type = "greek";
  8.  
  9.         if (args.length < 1 || args.length > 2)
  10.             System.out.println("Prea putini parametri.");
  11.         else if (args.length == 1) {
  12.             dim = Integer.parseInt(args[0]);
  13.             type = "latin";
  14.         } else if (args.length == 2) {
  15.             dim = Integer.parseInt(args[0]);
  16.             type = args[1];
  17.         }
  18.  
  19.         System.out.println("Dimensiune matrice: " + dim);
  20.         System.out.println("Limbaj: " + type);
  21.  
  22.         char[][] matrix = new char[50][50];
  23.  
  24.  
  25.         if(type.compareTo("latin") == 0)
  26.             for(int i = 0; i<dim; i++)
  27.                 matrix[0][i] = ((char)('A' + i));
  28.  
  29.         else if(type.compareTo("greek") == 0)
  30.             for(int i = 0; i<dim; i++)
  31.                 matrix[0][i] = (char)(('\u03B1' + i));
  32.  
  33.  
  34.         for(int i = 1; i<dim; i++) {
  35.             System.arraycopy(matrix[i - 1], 1, matrix[i], 0, dim);
  36.             System.arraycopy(matrix[i - 1], 0, matrix[i], dim - 1, 1);
  37.         }
  38.  
  39.         for (int i = 0; i < dim; i++) {
  40.             for (int j = 0; j < dim; j++)
  41.                 System.out.print( matrix[i][j] + " ");
  42.             System.out.println();
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement