Advertisement
gtw7375

Java - Somar e imprimir em metodos

Feb 11th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. public class Vendas{
  2.    
  3.     public static void main(String []args){
  4.        
  5.         Vendas resultado = new Vendas();
  6.         double[] vendas = {1000.00, 1500.00, 2000.00, 1800.00};
  7.         double soma = resultado.calculaSoma(vendas);
  8.         resultado.exibe(vendas, soma);
  9.      
  10.     }
  11.  
  12.     public double calculaSoma(double[] valor){
  13.        
  14.         double soma = 0.0;
  15.        
  16.         for(int i=0; i<valor.length; i++){
  17.                 soma += valor[i];
  18.         }
  19.        
  20.            
  21.         return soma;
  22.     }
  23.    
  24.     public static void exibe(double[] vendasIn, double somaIn){
  25.        
  26.         System.out.println("-------------------");
  27.         System.out.println(" TRIMESTRE DE VENDAS ");
  28.         System.out.println("-------------------");
  29.        
  30.         for(int j=1; j<=vendasIn.length; j++){
  31.             System.out.println("------" + j + "-------");
  32.         }
  33.         System.out.println("-------------------");
  34.         System.out.println("----- Total: " + somaIn);
  35.         System.out.println("-------------------");
  36.        
  37.         }
  38.        
  39.        
  40.        
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement