Advertisement
hackloper775

Vectores

Dec 30th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. /**
  4.  * Archivo Ejemplo.java Ejecuta : javac Ejemplo.java && java Ejemplo
  5.  *
  6.  * @author Atheyus
  7.  *
  8.  */
  9.  
  10. public class Ejemplo {
  11.  
  12.     public static void main(String[] args) {
  13.         String[][] matrizS = new String[2][2];
  14.         matrizS[0][0] = "Palabra uno fila 1";
  15.         matrizS[0][1] = "Palabra dos fila 1";
  16.         matrizS[1][0] = "Palabra uno fila 2";
  17.         matrizS[1][1] = "Palabra dos fila 2";
  18.        
  19.         Integer [] ejem = new Integer[5];
  20.         ejem[0] = 112;
  21.         ejem[1] = 132;
  22.         ejem[2] = 13;
  23.         ejem[3] = 111;
  24.         ejem[4] = 13;
  25.  
  26.         recorre(ejem); // Vemos el primer orden
  27.        
  28.         Arrays.sort(ejem); // Cambiamos el orden
  29.        
  30.         recorre(matrizS);
  31.        
  32.         recorre(ejem); // Vemos el nuevo orden
  33.        
  34.         System.out.println(Arrays.toString(matrizS));
  35.  
  36.     }
  37.  
  38.     private static void recorre(Integer [] x) {
  39.         for (int i = 0;i< (x.length);i++ ){
  40.             System.out.println("Numero "+i+" : "+x[i]);
  41.         }
  42.             System.out.println("Ultimo valor : "+x[x.length-1]); // Para obtener el ultimo valor se usa esta solucion
  43.     }
  44.    
  45.     private static void recorre(String[][] x) {
  46.  
  47.         for (int i = 0; i < x.length; i++) {
  48.             int columnas = x[i].length;
  49.             System.out.println("Fila : "+(i+1));
  50.             for (int o = 0; o < columnas; o++) {
  51.                 System.out.println("Valor : "+x[i][o]);
  52.             }
  53.  
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement