Advertisement
Guest User

Untitled

a guest
Aug 30th, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1.    //Faca um metodo que receba um array de inteiros e mostre na tela
  2.    //o maior e o menor elementos do array.
  3.    public static void mostrarMaxMin(int [] array){
  4.       //definir dados
  5.       int i = 0, max = array[0], min = array[0];
  6.       int [] resp = new int [2];
  7.      
  8.       resp[0] = max;
  9.       resp[1] = min;
  10.      
  11.       resp = mostrarMaxMin(array,i,resp);
  12.      
  13.       max = resp[0];
  14.       min = resp[1];
  15.      
  16.       System.out.println("O valor maximo do array eh: "+max);
  17.       System.out.println("O valor minimo do array eh: "+min);
  18.    }//end mostrarMaxMin
  19.    
  20.    public static int [] mostrarMaxMin(int [] array, int i, int [] resp){
  21.       //condicao de parada
  22.       if (i<array.length){
  23.          if (array[i] > resp[0]){ //resp[0] = max
  24.             resp[0] = array[i];
  25.          }//end if
  26.          if (array[i] < resp[1]){ //resp[1] = min
  27.             resp[1] = array[i];
  28.          }//end if
  29.          mostrarMaxMin(array,i+1,resp);
  30.       }//end if
  31.       return resp;
  32.    }//end mostrarMaxMin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement