-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDez.java
More file actions
36 lines (28 loc) · 912 Bytes
/
Copy pathDez.java
File metadata and controls
36 lines (28 loc) · 912 Bytes
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
package TodosExecicios;
//10.Escrevaumprogramaqueleiaumarraydenúmerosdousuárioatéqueousuárioinsiraumnúmerorepetido.
//Emseguida,imprimaaquantidadedenúmeroslidosantesdarepetição.
import java.util.Scanner;
import java.util.HashSet;
public class Nono {
public static void main (String []args) {
Scanner sc = new Scanner(System.in);
HashSet<Integer>numerosSet = new HashSet<>();
int cont = 0;
int num = 0;
System.out.println("Informe o tamanho do Array: ");
int tamanho = sc.nextInt();
Integer [] numero = new Integer[tamanho];
System.out.println("Informe os números do array: ");
System.out.println("Ou repita um numero para encerrar. ");
while(true) {
for (int i =0;i< tamanho; i++) {
numero[i] = sc.nextInt();
if(!numerosSet.add(numero[i])) {
break;
}
cont++;
}
System.out.println("Foram informados " + cont + " números.");
}
}
}