-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaiorValor.java
45 lines (33 loc) · 1.06 KB
/
MaiorValor.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
import java.util.Scanner;
public class MaiorValor {
public static void main(String[] args) {
Scanner ler = new Scanner(System.in);
final int SIZE = 10;
int[] a;
int menor, maior = 0;
a = new int[SIZE];
for (int i = 0; i < SIZE; i++) {
System.out.println("Insira o valor " + (i + 1) + ":");
a[i] = ler.nextInt();
}
menor = a[0];
for (int i = 0; i < SIZE; i++) {
if (a[i] > maior) {
maior = a[i];
} else if (a[i] < menor) {
menor = a[i];
}
}
for (int i = 0; i < SIZE; i++) {
if (i == 0) {
System.out.print("Vetor A = [" + a[i] + ", ");
} else if (i == (SIZE - 1)) {
System.out.println(a[i] + "]");
} else {
System.out.print(a[i] + ", ");
}
}
System.out.println("Maior valor: " + maior);
System.out.println("Menor valor: " + menor);
}
}