Can't get my while loop to work. If I move it up it works but not in the place its suppose to. Something to do with promting the numEntered?? Any ideas?
import java.util.*;
import javax.swing.*;
public class PhoneBook
{
public static void main(String[] args)
{
//int num;
String[] friendName = new String[20];
//String numString;
int[] numEntered = new int[20];
String entry = "", friendString = "";
String input = "", numString = "";
int x = 0;
int highestSub = friendName.length - 1;
Arrays.fill(friendName, "zzz");
friendName[x] = JOptionPane.showInputDialog(null, "Enter in the name of your friend or zzz to exit");
numString = JOptionPane.showInputDialog(null, "Enter the phone number of " + friendName[x]);
numEntered[x] = Integer.parseInt(numString);
while(!friendName[x].equals("zzz") && x < highestSub)
{
friendString = friendString + friendName[x] + "\n";
numString = numString + numEntered [x] + "\n";
++x;
if(x < highestSub)
friendName[x] = JOptionPane.showInputDialog(null, "Enter in the name of your friend or zzz to exit");
}
numEntered = x;
JOptionPane.showMessageDialog(null, "You entered in the names and phone numbers of " + numEntered + " friends: \n" + friendString);
//Arrays.sort(friendName, 0, numEntered); //change to sort by name
x = Arrays.binarySearch(friendName, entry);
if(x >= 0 && x < numEntered)
JOptionPane.showMessageDialog(null, "Your friend xx,xxx has the phone number xxx");//need to fix
}
}
