Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Faca um metodo que receba um array de inteiros e mostre na tela
- //o maior e o menor elementos do array.
- public static void mostrarMaxMin(int [] array){
- //definir dados
- int i = 0, max = array[0], min = array[0];
- int [] resp = new int [2];
- resp[0] = max;
- resp[1] = min;
- resp = mostrarMaxMin(array,i,resp);
- max = resp[0];
- min = resp[1];
- System.out.println("O valor maximo do array eh: "+max);
- System.out.println("O valor minimo do array eh: "+min);
- }//end mostrarMaxMin
- public static int [] mostrarMaxMin(int [] array, int i, int [] resp){
- //condicao de parada
- if (i<array.length){
- if (array[i] > resp[0]){ //resp[0] = max
- resp[0] = array[i];
- }//end if
- if (array[i] < resp[1]){ //resp[1] = min
- resp[1] = array[i];
- }//end if
- mostrarMaxMin(array,i+1,resp);
- }//end if
- return resp;
- }//end mostrarMaxMin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement