Advertisement
Guest User

Untitled

a guest
Nov 20th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package Paquete;
  2.  
  3. public class MatrizSimetrica
  4. {
  5.     private int valores[];
  6.     private int cantidad;
  7.     private int filas;
  8.    
  9.     public MatrizSimetrica(int cantidad)
  10.     {
  11.         this.filas = cantidad;
  12.         this.cantidad = cantidad * 2;//(cantidad - 1) / 2;
  13.         valores = new int[this.cantidad];
  14.     }
  15.    
  16.     public void set(int fila, int columna, int valor)
  17.     {
  18.         if(fila + columna >= cantidad)
  19.             valores[fila + columna - cantidad] = valor;
  20.         else if(fila != columna)
  21.             valores[fila + columna] = valor;
  22.     }
  23.    
  24.     public int get(int fila, int columna)
  25.     {
  26.         if(fila + columna >= cantidad)
  27.             return valores[fila + columna - cantidad];
  28.         else if(fila == columna)
  29.             return -1;
  30.        
  31.         return valores[fila + columna];
  32.     }
  33.    
  34.     public String toString()
  35.     {
  36.         String salida = "";
  37.        
  38.         for(int i = 0; i < filas; i++)
  39.         {
  40.             for(int j = 0; j < filas; j++)
  41.                 salida += i + " " + j + " " + get(i, j) + "\n";
  42.         }
  43.        
  44.         return salida;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement