-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaiorMenor.java
More file actions
40 lines (33 loc) · 1.22 KB
/
Copy pathMaiorMenor.java
File metadata and controls
40 lines (33 loc) · 1.22 KB
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
import java.util.Scanner;
public class MaiorMenor {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int opcao;
do {
System.out.println("1 - Ler valores");
System.out.println("2 - Sair");
System.out.print("Digite a opção: ");
opcao = sc.nextInt();
if (opcao == 1) {
System.out.print("Quantos numeros gostaria de testar: ");
int quantidade = sc.nextInt();
int menor = 0;
int maior = 0;
for (int i = 0; i < quantidade; i++) {
System.out.print("Digite o " + (i + 1) + "° numero: ");
int numero = sc.nextInt();
menor = numero;
if (maior < numero) {
maior = numero;
} else if (menor == 0 || menor == 1) {
menor = numero;
}
}
System.out.println("O maior: " + maior);
System.out.println("O menor: " + menor);
}
} while (opcao == 1);
System.out.println("Fim da execução");
sc.close();
}
}