Advertisement
H4cktz

Untitled

Oct 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. 7 Leia um vetor de 12 posições e em seguida ler também dois valores X e Y quaisquer correspondentes a duas posições no vetor. Ao final seu programa deverá escrever a soma dos valores encontrados nas respectivas posições X e Y.
  2.  
  3. import java.util.Scanner;
  4. public class Lista05_n07 {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         int [] vet = new int [12];
  9.         int x,y;
  10.         for (int i=0; i < vet.length;i++){
  11.             System.out.print("Digite o "+(i+1)+"° número");
  12.             vet[i] = scan.nextInt();
  13.         }
  14.         System.out.println("Digite o valor x");
  15.         x=scan.nextInt();
  16.         System.out.println("Digite o valor y");
  17.         y=scan.nextInt();
  18.         System.out.println("A soma é "+(vet[x]+vet[y]));
  19.     }
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement