Last active
December 17, 2015 14:59
-
-
Save gmfc/5628157 to your computer and use it in GitHub Desktop.
Aula 22.
Em construção...
EDIT completo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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