Advertisement
Edosecs

main

May 5th, 2023
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. import fond.io.*;
  2.  
  3. public class ProvaMatriceDiStringhe {
  4.  
  5.     public static void main(String[] args) {
  6.         InputWindow in = new InputWindow();
  7.         OutputWindow out = new OutputWindow();
  8.        
  9.         int dim = in.readInt("Inserisci la dimensione della matrice:");
  10.         String[][] m = new String[dim][dim];
  11.        
  12.         for(int i=0; i<dim; i++) {
  13.             for(int j=0; j<dim; j++) {
  14.                 m[i][j] = in.readString("Inserisci la stringa di posizione " + i + ";" + j + " :");
  15.             }
  16.         }
  17.        
  18.         MatriceDiStringhe mds = new MatriceDiStringhe(m);
  19.         out.writeln("Matrice Inserita:");
  20.         out.writeln(m.toString());
  21.        
  22.         boolean continua = true;
  23.         while (continua) {
  24.             int i = in.readInt("Inserisci un indice di riga (0-" + (dim-1) + ") o -1 per uscire: ");
  25.            
  26.             if (i == -1) {
  27.                 continua = false;
  28.             } else if (i < 0 || i >= dim) {
  29.                 out.writeln("Indice non valido!");
  30.             } else {
  31.                 out.writeln("Minimo della riga " + i + ": "+mds.primaInRiga(i));
  32.             }
  33.         }
  34.        
  35.         MatriceDiStringhe sottomatrice = new MatriceDiStringhe(new String[dim/2][dim/2]);
  36.        
  37.         for (int i=0; i<dim; i+=2) {
  38.             for (int j=0; j<dim; j+=2) {
  39.                 sottomatrice[i/2][j/2] = mds[i][j];
  40.             }
  41.         }
  42.            
  43.         out.writeln("Sottomatrice degli elementi con indici dispari:");
  44.         out.writeln(sottomatrice);
  45.     }
  46. }
  47.  
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement