Advertisement
0no

Maior elemento vetor - Recursividade

0no
Oct 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. // Função recursiva que mostre o maior elemento de um vetor.
  2.  
  3. class Inicio{
  4.     public static void main(String[] args) {
  5.         int[] a = {5, 5, 8, 9, 6};
  6.         int maior = array(a, (a.length - 1), a[a.length - 1]);
  7.         System.out.println("O maior é " + maior);
  8.     }
  9.    
  10.     public static int array(int[] b, int num, int maior){
  11.         if(num >= 0){
  12.             if(b[num] > maior){
  13.                 maior = b[num];
  14.             }
  15.             return array(b, num - 1, maior);
  16.         }
  17.         return maior;
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement