Hi,
When I enter the longest first name third, the program works well.
However, if the longest first name is entered either first of second,
the dialog box does not appear. I've been trying different options,
all with no luck and was hoping someone could point me in the right
direction.
Thanks!
import javax.swing.JOptionPane;
/**
*
* @author John
*/
public class JavaArray {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String fullNames[]=new String[3];
for(int i=0;i<3;i++){
fullNames[i] = JOptionPane.showInputDialog(null,"Enter First &
Last name of person number " + (i+1));
}
String[] FirstName1 = fullNames[0].split(" ");
String[] FirstName2 = fullNames[1].split(" ");
String[] FirstName3 = fullNames[2].split(" ");
int length1=FirstName1[0].length();
int length2=FirstName2[0].length();
int length3=FirstName3[0].length();
int i=0;
int j=0;
if ((length1>=length2)&(length1>=length3)){
i=0; j=1;
}
if ((length2>=length3)&(length2>=length1)){
i=1;j=0;
}
if ((length3>=length2)&(length3>=length1)){
i=2;j=1;
JOptionPane.showMessageDialog(null,fullNames[i]+" has
longer first name than " + fullNames[j]);
}
}
}
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---