New2,
You have two problems, though only one is causing the symptoms you
described. I could just give you the answer as many often do, but I
think you would get more out of it if I simply steer you in the right
direction. Check the placement of your curly braces to fix the problem
you described. Also review usage of boolean operators to correct the
less obvious issue.
Let me know if you still need help and I will send you the solution.
New2Programming wrote:
> 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]);
>
> }
> }
> }
>
> >
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.0.233 / Virus Database: 270.10.20/1943 - Release Date: 02/10/09
> 07:20:00
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---