Skip to content

Instantly share code, notes, and snippets.

@gmfc
Last active December 17, 2015 14:59
Show Gist options
  • Select an option

  • Save gmfc/5628157 to your computer and use it in GitHub Desktop.

Select an option

Save gmfc/5628157 to your computer and use it in GitHub Desktop.
Aula 22. Em construção... EDIT completo
import javax.swing.*;
class vetores{
public static void main(String [] args){
int[] vetor;
int tamanho,x,iPosicao;
do{
tamanho = Integer.parseInt(JOptionPane.showInputDialog("Entre com o tamanho do vetor"));
}while(tamanho<=0);
vetor = new int[tamanho];
leVetorInteiros(vetor,tamanho);
exibeVetorInteiros(vetor,tamanho);
x = Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero que deseja buscar"));
iPosicao = buscaVetor(vetor,tamanho,x);
if(iPosicao !=0){
saida("A posição de "+x+" é: " + iPosicao);
}else{
saida(x+" Não esta no vetor!");
}
}
public static void leVetorInteiros (int v[ ], int tam){
for(int i = 0;i < tam;i++){
v[i] = Integer.parseInt(JOptionPane.showInputDialog("Entre com o valor da posição: "+i));
}
}
public static void exibeVetorInteiros (int v[ ], int tam){
String saida = "";
for(int i=0; i<tam;i++){
saida = saida + "vetor["+i+"] = "+v[i]+"\n";
}
saida(saida);
}
public static int buscaVetor (int v[ ], int tam, int x){
int i;
for(i = 0;i<tam;i++){
if(v[i]==x){
return i;
}
}
return -1;
}//FAZER ISSO AQUI!!!
//Saida
public static void saida(String saida){
JOptionPane.showMessageDialog(null,saida);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment