Hi Béatrice,
Concerning your problem 1:
the variable name is not defined: you defined an ARRAY called name, so you should use name[i] instead of name. Then the split method can be applied.
Problem 2:
You did not create, nor instantiate "longestName": is it a String? an integer? a double?... You should write the same way as you did for counter,max, totalname, longest: assign longestName to the right primitive type, and eventually initialize it to a start value (""?).
You should also follow the naming rules for variables: 1st character is lowercase, each following word of the name starts with uppercase. So write "totalName" instead of "totalname"!
Marco



Béatrice [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
-~----------~----~----~----~------~----~------~--~---

Reply via email to