Advertisement
cesarnascimento

manipulando arrays aula 48 soma todos elementos

May 25th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. package ex6;
  2.  
  3. public class excript {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         int[] arrayInt = new int[10];
  8.         arrayInt[0] = 10;
  9.         arrayInt[1] = 20;
  10.         arrayInt[2] = 30;
  11.         arrayInt[3] = 30;
  12.         arrayInt[4] = 10;
  13.         arrayInt[5] = 15;
  14.         arrayInt[6] = 25;
  15.         arrayInt[7] = 90;
  16.         arrayInt[8] = 5;
  17.         arrayInt[9] = 3;
  18.        
  19.        
  20.        
  21.         int soma = arrayInt[0]+ arrayInt[1] + arrayInt[2];
  22.         // somar todos os elementos de uma vez
  23.        
  24.         System.out.println("A soma Γ© do array 0, 1 e 2 Γ©: "+soma);
  25.        
  26.         int soma2 = 0;
  27.         for(int i = 0; i <10 ; i++){
  28.             soma2 += arrayInt[i];
  29.            
  30.         }
  31.         System.out.println("A soma de todos elementos Γ©: "+soma2);
  32.  
  33.        
  34.     }
  35.     /* CΓ©sar N. */
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement