You need names not numbers so you could set up namesArray like this:
//set up the names array
String[] names = new String[members];
Why not work with strings in the first place then you don't have to
Integer.parseInt
Like Marco stated you need string types to make names[0].split(" ")
work.
I see no problem with instantiating int longest = 0;
You just did not use it yet to get the one name that is.
Hint: Try some while loops and if statements to get it.
On Aug 22, 2:16 am, Béatrice [email protected]
<[email protected]> wrote:
> Hi !
> I've got a problem with the homework of la 1036.
> I understand now how the split method works. But I can't declare it
> correctly, so I have two error messages.
> Here's my code (I found part of it in another mail).
> Can you help me to understand how it works ?
>
> import javax.swing.JOptionPane;
>
> public class OwnJavaArray {
>
> public static void main(String[] args) {
> int[] name = new int[10];
> int counter;
> int max = 0;
> int totalname = 3;
> int longest = 0;
>
> // Prompt a user to enter numbers
> for (counter = 0; counter < totalname; counter++){
>
> name [counter] = Integer.parseInt
> (JOptionPane.showInputDialog("Enter first name and last name of family
> members until " + totalname + " names are entered"));
>
> String[] names = name.split(" "); [Pb1]
> if (names[0].length() > longest){
> longest = names[0].length();
> longestName = name;} [Pb2]
>
> // Display the greatest number.
> JOptionPane.showMessageDialog(null,"The name with the longest
> first name value is " + name);
> }
>
> }
> }
>
> Problems :
> [Pb1]. cannot find symbol : method split
> [Pb2]. longestName is not defined; but I don't know how to to it. I
> tried with int but it doen't work.
> And I am not sure that longest is well declared.
>
> Thank you
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---