Tammy,
I used an aray of arrays to keep track of the names. Then I used an index ( 
init to 0 ) to keep track of which had the longest first name.
Hope this might help.
importjavax.swing.JOptionPane;publicclassFindLongestName {/[EMAIL 
PROTECTED]/staticintname_count= 3;publicstaticvoidmain(String[] args) {// 
TODOAuto-generated method stubString[][] names = 
String name = 
name=JOptionPane.showInputDialog(
String[] tempArray = name.split(
names[count][0] = tempArray[0];
names[count][1] = tempArray[1];
}
System.
maxIndex = count;
} 
}
System.
}
}
ToddnewString[name_count][2];"";for(intcount = 0; name_count> count; count++ ) 
{"Please enter name #"+(count+1) );" ");intmaxIndex = 0;for(intcount = 0; 
names.length> count; count++ ) {out.println( "Name: "+ names[count][0] + " "+ 
count );if( names[maxIndex][0].length() < names[count][0].length() ) 
{out.println("The longest name is: "+names[maxIndex][0]+" "+names[maxIndex][1]);


----- Forwarded Message ----
From: "Estes, Tammy" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]; Free Java Programming Online Training Course By Sang 
Shin <[email protected]>
Sent: Thursday, August 28, 2008 12:11:07 PM
Subject: [java programming] Re: MyOwnJavaArrayProject Homework Questions


I'm assuming there are various ways to do that program. I'm interested in 
learning about the different ways in order to advance my programming skills and 
type LESS. :)

Tammy L. Estes
DAFS ~ OIT ~ ADAM 
Voice 207-624-8287
[EMAIL PROTECTED]

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On 
Behalf Of abstract26
Sent: Thursday, August 28, 2008 1:07 PM
To: Free Java Programming Online Training Course By Sang Shin
Subject: [java programming] Re: MyOwnJavaArrayProject Homework Questions


You can use a single array to hold three full names.

Note, that the split function returns an array itself, therefore
within a loop you can extract out the first name and second name in
another String array which holds the outcome from the split
function...

Something like this

String []fname;

fname=names[i].split(" ");
fname[0] will hold the first name
fname[1] will hold the last name

Just use fname[0].length() for comparison for all three first names.

I think its better solution then creating three sepearte arrays.


On Aug 28, 1:07 pm, "Estes, Tammy" <[EMAIL PROTECTED]> wrote:
> I completed the homework already for MyOwnJavaArrayProject, got it to
> work and passed it in.
>
> Now a day or two after I start thinking about "easier ways" I could have
> written my program. It is funny how this course really makes you think
> doesn't it??
>
> Anyway... this is my question:
>
> Is this:
>
> //System.out.println("Splitting the three names now...");
>
> String[] FirstPersonFirstName = strArray[0].split(splitter);
>
>  String[] SecondPersonFirstName = strArray[1].split(splitter);
>
>  String[] ThirdPersonFirstName = strArray[2].split(splitter);
>
> The absolute BEST way to split the three or can I use something like
> this?
>
> String [] strFname = {" ", " ", " ", }; // an array to hold the 3 first
> names
>
> for (int i = 0; i < strFname.length; i++){
>
>              System.out.println("Beginning loop now to split names
> now...");
>
>              String[] strFname = strArray[0].split{splitter);  
>
>         }
>
> I tried the last line and get an error ( ; needed) but I think I'm close
> to getting something I can easily work with.
>
> Just trying to find easier ways to write it all out.
>
> In any case, I did the additional work as PRACTICE to make sure I
> understand arrays and can work with them easily without putting too much
> thought into it. I also added ternary operators in the second version in
> place of the if-else statement.
>
> So any thoughts on this above would be helpful!
>
> Thanks,
>
> Tammy L. Estes
>
> DAFS ~ OIT ~ ADAM
>
> Voice 207-624-8287
>
> [EMAIL PROTECTED]




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to