Txerrinko

MetodosArray

Mar 18th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package Ejercicio7;
  2.  
  3. import java.io.IOException;
  4.  
  5. import Ejercicio5.Consola;
  6.  
  7. public class MetodosArray {
  8.  
  9.    
  10.    
  11.  
  12.     static int [] tabla3=new int [20];
  13.     /**
  14.      * @param args
  15.      */
  16.     static int i;
  17.     static int j;
  18.     static int b;
  19.     static int k=0;
  20.     static int previos1=-10;
  21.     static int previos2=-13;
  22.     static int num;
  23.    
  24.    
  25.    
  26.     public static  void cargaDatos ( int[] tabla1 ,int[] tabla2  ) throws IOException{
  27.         for (i=0;i<tabla1.length;i++){
  28.             System.out.println("Introduce numero");
  29.             num=Consola.leeInt();
  30.            
  31.             if ( num < previos1){
  32.                
  33.                 System.out.println("Numero menos que el anterior");
  34.                 }
  35.             else
  36.                 tabla1[i]=num;
  37.                 previos1=num;
  38.        
  39.         }
  40.        
  41.        
  42.         for (j=0;j<tabla2.length;j++ ){
  43.             System.out.println("Introduce numero");
  44.             num=Consola.leeInt();
  45.             if ( num < previos2){
  46.                
  47.                 System.out.println("Numero menos que el anterior");
  48.                 }
  49.             else  
  50.                  tabla2[j]=num;
  51.                  previos2=num;
  52.         }
  53.    
  54.        
  55.        
  56.     }
  57.    
  58.     public static void mezclaArrays (int []tabla3,int []tabla2 , int []tabla1){
  59.         for (k=0; k<tabla3.length;k++)
  60.            
  61.            
  62.             if (i<tabla1.length && tabla1[i]<=tabla2[j]  ){
  63.             tabla3[k]=tabla1[i];
  64.             i++;
  65.             }
  66.            
  67.             else{
  68.             if (j<tabla2.length){
  69.             tabla3[k]=tabla2[j];
  70.             j++;
  71.                         }
  72.                    }
  73.              }  
  74.        
  75.    
  76.    
  77.    
  78.     public void ver (int [] tabla3){
  79.  
  80.         for ( int b=0;b<tabla3.length;b++){
  81.            
  82.             System.out.print(+tabla3[k]);
  83.            
  84.         }
  85.        
  86.        
  87.     }
  88.    
  89.    
  90.  
  91.    
  92.    
  93.    
  94.     public static void main(String[] args) {
  95.         // TODO Auto-generated method stub
  96.  
  97.         MetodosArray elem =new MetodosArray();
  98.     //  elem.cargaDatos(10, 10);
  99.     //  elem.mezclaArrays();
  100.         elem.ver(tabla3);
  101.        
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment