Advertisement
LightProgrammer000

Conserta_matriz

Apr 11th, 2020
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package Tarefas_4;
  2.  
  3. public class EX_05
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         // Vetor
  8.         int vetor [] = popular_vetor();
  9.  
  10.         // Chamada de funcoes
  11.         relatorio(vetor);
  12.         conserta_vetor(vetor);
  13.         relatorio(vetor);
  14.     }
  15.  
  16.     private static int[] popular_vetor()
  17.     {
  18.         int vet [] = new int[25];
  19.  
  20.         for (int i = 0; i < vet.length; i++)
  21.         {
  22.             vet[i] = i - 10;            
  23.         }
  24.  
  25.         return vet;
  26.     }
  27.  
  28.     private static void relatorio(int[] vet)
  29.     {
  30.         System.out.print("\n------------------------------------------------");
  31.        
  32.         for (int i = 0; i < vet.length; i++)
  33.         {
  34.             System.out.printf("\n Indice [%d]: %d", i+1, vet[i]);            
  35.         }
  36.  
  37.         System.out.println("\n------------------------------------------------");
  38.     }
  39.  
  40.     private static int [] conserta_vetor(int[] vet)
  41.     {
  42.         for (int i = 0; i < vet.length; i++)
  43.         {
  44.             if (vet[i] < 0)
  45.             {
  46.                 vet[i] = 0;                
  47.             }
  48.         }
  49.  
  50.         return vet;
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement