-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuscarEmVetor.java
More file actions
37 lines (32 loc) · 1.21 KB
/
Copy pathBuscarEmVetor.java
File metadata and controls
37 lines (32 loc) · 1.21 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
import java.util.Scanner;
public class BuscarEmVetor {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int opcao;
do {
System.out.println("Opções");
System.out.println("1-Buscador de numeros");
System.out.println("2-Sair");
System.out.print("Digite a opção: ");
opcao = sc.nextInt();
if (opcao == 1) {
System.out.print("Quantos numeros vai digitar: ");
int tamanho = sc.nextInt();
int numeros[] = new int[tamanho];
for (int i = 0; i < tamanho; i++) {
System.out.print("Digite o " + (i + 1) + "° numero: ");
int numero = sc.nextInt();
numeros[i] = numero;
}
System.out.print("Buscar numero: ");
int buscar = sc.nextInt();
for (int i = 0; i < tamanho; i++) {
if (buscar == numeros[i]) {
System.out.println("O numero " + numeros[i] + " está no indice: " + i);
}
}
}
} while (opcao == 2);
sc.close();
}
}