Txerrinko

Matriz1

Mar 18th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. package Ejercicio2;
  2.  
  3. import java.io.IOException;
  4.  
  5. public class Matriz12 {
  6.  
  7.     private int[][]clase1;
  8.    
  9.     private int nf;
  10.     private int nc;
  11.    
  12.     static final int  NF=2;
  13.    
  14.     static final int NC=5;
  15.    
  16.    
  17.     Matriz12()
  18.     {
  19.         clase1=new int[NF][NC];
  20.     }
  21.    
  22.     Matriz12(int pnf,int pnc)
  23.     {
  24.         nf=pnf;
  25.         nc=pnc;
  26.        
  27.     }
  28.    
  29.     public void cargarporfilas() throws IOException
  30.     {
  31.         int num,i,j;
  32.         for(i =0;i<clase1.length;i++)
  33.         {
  34.             for(j=0;j<clase1[i].length;j++)
  35.             {
  36.                 System.out.println("Introduzca numeros");
  37.                 num = Consola.leeInt();
  38.                 clase1[i][j]=num;
  39.             }
  40.         }
  41.     }
  42.    
  43.    
  44.     public void cargarporColumnas() throws IOException
  45.     {
  46.         int num,i,j;
  47.         for(j =0;j<clase1[0].length;j++)
  48.         {
  49.             for(i=0;i<clase1.length;i++)
  50.             {
  51.                 System.out.println("Introduzca numeros");
  52.                 num = Consola.leeInt();
  53.                 clase1[i][j]=num;
  54.             }
  55.         }
  56.     }
  57.    
  58.     public void ver()
  59.     {
  60.         int i,j;
  61.         for(i=0;i<clase1.length;i++)
  62.         {
  63.             for(j=0;j<clase1[i].length;j++)
  64.             {
  65.                 System.out.print(clase1[i][j]+ " ");
  66.                
  67.             }
  68.             System.out.println();
  69.         }
  70.     }
  71.    
  72.     public void invertirFilas() throws IOException
  73.     {
  74.         int i,j,k,cont;
  75.    
  76.         for(i=0;i<clase1.length;i++)
  77.         {
  78.             cont=1;
  79.             for(j=0;j<clase1[i].length-cont;j++)
  80.             {
  81.                 k=clase1[i][j];
  82.                 clase1[i][j]=clase1[i][clase1[i].length-cont];
  83.                 clase1[i][clase1[i].length-cont]=k;
  84.                 cont++;
  85.             }
  86.         }
  87.    
  88.     }
  89.    
  90.     public boolean intercambiarFilas(int nf1, int nf2)
  91.     {
  92.  
  93.         int []aux =null;
  94.         if(nf1<clase1.length & nf2<clase1.length)
  95.  
  96.         aux=clase1[nf1-1];
  97.         clase1[nf1-1]=clase1[nf2-1];
  98.         clase1[nf2-1]=aux;
  99.        
  100.                
  101.            
  102.        
  103.        
  104.        
  105.        
  106.        
  107.        
  108.         return false;
  109.        
  110.     }
  111.      
  112.     // public static int []Mayorfila    // parametros array de una fila
  113.  
  114.         /*
  115.  
  116.  
  117.       int j,i,imax;
  118.       int max=-999;
  119.  
  120. for(int i=0; i<Asignaturas.length;i++)
  121. {
  122. int suma=0;
  123.            
  124.  
  125.          for (j=0; j<Asignaturas[i].length;j++){
  126.  
  127.  
  128.             suma+=Asignaturas M [i] [j]
  129.                  }
  130.  
  131.  
  132.         media=Suma/Asignaturas[i].length
  133.  
  134.  
  135.  
  136. }
  137.            
  138.  
  139.        if (media>max) {
  140.  
  141.               max=media
  142.              imax=1;
  143.         }
  144.                  int []dev=Asignaturas[max];
  145.         return Asignaturas[imax];
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. */
  155.    
  156.    
  157.    
  158. }
Advertisement
Add Comment
Please, Sign In to add comment