Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- import java.util.Scanner;
- public class Lista05_n07 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int [] vet = new int [12];
- int x,y;
- for (int i=0; i < vet.length;i++){
- System.out.print("Digite o "+(i+1)+"° número");
- vet[i] = scan.nextInt();
- }
- System.out.println("Digite o valor x");
- x=scan.nextInt();
- System.out.println("Digite o valor y");
- y=scan.nextInt();
- System.out.println("A soma é "+(vet[x]+vet[y]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement