ANALIZEM ESSE CODIGO QUE VERAO O ERROO!!
NA HORA DE ARMAZENAR OS DADOS PARA DEPOIS IMPRIMIR NAO FUNCIONA CERTO.
/*Agenda Telefonica que armazera Nome, telefone e endereço da pessoa e
depois imprimi os mesmos.*/
import javax.swing.JOptionPane;
class AgendaTel
{
public static void main(String args[])
{
String nome[]=new String[5];
String endereço[]=new String[5];
int cont=0, telefone[]=new int[5];
int endereço1, telefone1, b=0, c=0;
String nomepesq;
for(int i=0;i<5;i++)
{
nome[i]=JOptionPane.showInputDialog("Digite o nome:");
telefone[b]=Integer.parseInt(JOptionPane.showInputDialog("Digite o telefone: (Sem pronto e nem traço.)"));
endereço[c]=JOptionPane.showInputDialog("Digite o endereço:");
}
nomepesq=JOptionPane.showInputDialog("Digite o nome a ser pesquisado: ");
for(int i=0;i<5;i++)
{
if(nome[i].equals(nomepesq))
cont++;
System.out.println("RESULTADOS DA PESQUISA:");
System.out.println("Nome: "+nomepesq);
System.out.println("Telefone: "+telefone[0]);
System.out.println("Endereço: "+endereço[0]);
JOptionPane.showMessageDialog(null, "Nome:"+" "+nomepesq+"\n Telefone:"+" "+telefone[0]+ "\n Endereço:" +" "+endereço[0]);
}
System.exit(0);
}
}
Erro esta na sua apresentação vc esta passando o indice 0 qndo nomePesquisado for igual ao nome esta no Array
for(int i=0;i<5;i++)
{
if(nome[i].equals(nomepesq))
{
cont++;
System.out.println("RESULTADOS DA PESQUISA:");
System.out.println("Nome: "+nomepesq);
System.out.println("Telefone: "+telefone[i]);
System.out.println("Endereço: "+endereço[i]);
JOptionPane.showMessageDialog(null, "Nome:"+" "+nomepesq+"\n Telefone:"+" "+telefone[i]+ "\n Endereço:" +" "+endereço[i]);
break;
}
}
Segue o codigo arrumado amigo.
[code]import javax.swing.JOptionPane;
class AgendaTel {
public static void main(String args[]) {
String nome[] = new String[5];
String endereço[] = new String[5];
int cont = 0, telefone[] = new int[5];
int endereço1, telefone1;
String nomepesq;
for (int i = 0; i < 5; i++) {
nome[i] = JOptionPane.showInputDialog("Digite o nome:");
telefone[i] = Integer.parseInt(JOptionPane.showInputDialog("Digite o telefone: (Sem pronto e nem traço.)"));
endereço[i] = JOptionPane.showInputDialog("Digite o endereço:");
}
nomepesq = JOptionPane.showInputDialog("Digite o nome a ser pesquisado: ");
for (int i = 0; i < 5; i++) {
if (nome[i].equals(nomepesq)) {
System.out.println("RESULTADOS DA PESQUISA:");
System.out.println("Nome: " + nome[i]);
System.out.println("Telefone: " + telefone[i]);
System.out.println("Endereço: " + endereço[i]);
JOptionPane.showMessageDialog(null, "Nome:" + " " + nome[i]
+ "\n Telefone:" + " " + telefone[i] + "\n Endereço:"
+ " " + endereço[i]);
break;
}
}
System.exit(0);
}
}[/code]