-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx02_4.java
More file actions
31 lines (24 loc) · 848 Bytes
/
Ex02_4.java
File metadata and controls
31 lines (24 loc) · 848 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
/* Dado um vetor v = {91, 10, 50, 89, 45, 80, 2, 45, 3, 105, 95,
13, 26, 49, 50}, criar um programa a que leia um número e
verifique e imprima na tela se este número existe no vetor.
* Resolvido pelo aluno >> Gustavo Mota Macedo */
import java.util.Scanner;
public class Ex02_4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] v = {91, 10, 50, 89, 45, 80, 2, 45, 3, 105, 95,
13, 26, 49, 50};
System.out.println("Digite um numero para ser impresso na tela:");
int numero = sc.nextInt();
boolean encontrado = false;
for (int i = 0; i < v.length; i++) {
if (numero == v[i]) {
encontrado = true;
System.out.println("=====" + numero + "=====");
break;
}
}
if (!encontrado)
System.out.println("Numero não encontrado :( ");
}
}