-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path34.java
More file actions
39 lines (31 loc) · 1.1 KB
/
34.java
File metadata and controls
39 lines (31 loc) · 1.1 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
/*******************************************************************************
* 34) Escreva um programa que leia um conjunto de números positivos e exiba o
* menor e o maior. Suporemos que o número de elementos deste conjunto não é
* conhecido, e que um número negativo será utilizado para sinalizar o fim dos
* dados.
*******************************************************************************/
import java.util.Scanner;
public class Exercicio {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
int numeroAtual,maior,menor;
boolean primeiro=true;
System.out.print("Digite um número (negativo para sair): ");
numeroAtual = entrada.nextInt();
if(numeroAtual>=0){
menor = numeroAtual;
maior = numeroAtual;
while(numeroAtual>=0){
System.out.print("Digite outro número: ");
numeroAtual = entrada.nextInt();
if(numeroAtual > maior){
maior = numeroAtual;
}
if(numeroAtual < menor && numeroAtual >= 0){
menor = numeroAtual;
}
}
System.out.println("\nO maior número foi "+maior+" e o menor foi "+menor);
}
}
}