-
Notifications
You must be signed in to change notification settings - Fork 0
/
Atividade4.java
68 lines (60 loc) · 2.04 KB
/
Atividade4.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package atividade4;
import java.util.Scanner;
/**
*
* @author Ana Vilaca
*/
public class Atividade4 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner lervetor = new Scanner(System.in);
int vetor[];
vetor = new int[10];
int maior;
int menor;
int media;
int soma;
soma = 0;
maior = 0;
menor = 9999999;
for (int i = 0; i < 10; i++) {
//recebe os 10 valores para armazenar no vetor
System.out.printf("Digite o elemento da posicao " + (i + 1) + ": ");
vetor[i] = lervetor.nextInt();
System.out.println(" ");
//a cada novo valor a soma e incrementada
soma = soma + vetor[i];
}
//compara os valores das posicoes com os valores setados para as variaveis maior e menor e a variavel recebe
//o valor da posicao comparada caso obedeca ao criterio do if
for (int i = 0; i < 10; i++) {
if (vetor[i] >= maior) {
maior = vetor[i];
}
if (vetor[i] <= menor) {
menor = vetor[i];
}
}
//imprime o vetor na tela
System.out.println("VETOR");
for (int i = 0; i < 10; i++) {
System.out.print(vetor[i] + " ");
System.out.println(" ");
}
media = soma / 10;
//imprime na tela a media e o maior e menor valor armazenados dentro do vetor
System.out.println(" a media e " + (media) + " ");
System.out.println(" ");
System.out.println(" o menor valor e " + (menor) + " ");
System.out.println(" ");
System.out.println(" o maior valor e " + (maior) + " ");
System.out.println(" ");
}
}