-----Original Message-----
From: Moria Shebsovich 
Sent: Thursday, September 17, 2009 10:33 AM
To: '[email protected]'
Subject: RE: [java programming] LAB1036 - not getting any output

Hi James,
Yes, you can use split in this case but I think that you are mixing
between splitting name / name and first name / last name -- that the
reason you are not getting an output.
Here is my solution - you will see an output but for three members only
(try to workout from 3 to 6 members):

public static void main(String[] args) {
        //Declare counter and number of names to be entered (members)
        int i=0;
        int members=3;
        String[] names = new String[members];
        //Input name

        for (members = 0; members < 3; members++) {
            names[members] = JOptionPane.showInputDialog("Please enter
the family member name");
        }
      // if(i<members){//i++;
      //      names[i]=JOptionPane.showInputDialog("What is your
name?");
       //     i++;
      // }
       //else{
       // Get the first name from a name string using split()
instance(non-static) method
            String[] nameArray0 = names[0].split(" ");
            String[] nameArray1 = names[1].split(" ");
            String[] nameArray2 = names[2].split(" ");
           // String[] nameArrayForPerson2 = person2NameInstance.split
(" ");

          // Get the lengths of strings using length() instance (non
static) method
            int lengthFirstName0 = nameArray0[0].length();
            int lengthFirstName1 = nameArray1[0].length();
            int lengthFirstName2 = nameArray2[0].length();

          // Compare the lengths of the first names between person1 and
person2
            if (lengthFirstName0 > lengthFirstName1){
                System.out.println(nameArray0[0] +
                              " has longer first name than " +
                              nameArray1[0]);
    }
            if(lengthFirstName1>lengthFirstName2){
                System.out.println(nameArray1[0]+" has longer first name
than "+nameArray2[0]);}
            else{System.out.println(nameArray2[0]+" has the longest
first name.");}

    }
//    }

} 

I hope it helps,
Moria.



-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of James
Sent: Thursday, September 17, 2009 4:43 AM
To: Free Java Programming Online Training Course By Sang Shin
Subject: [java programming] LAB1036 - not getting any output


Hi,
Bit late joining the course so trying to catch up!

I'm on the JavaArray homework from LAB-1036 but I'm having some
problems. It looks ok to me, but when I run I get asked my name and
then it finished. No error messages though. Have I used split right?
And is there anyway to keep all the split names in a single array?
e.g. [first][last]

Cheers,
James

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.swing.JOptionPane;
/**
 *
 * @author bmb3jkrk
 */
public class OwnJavaArray {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //Declare counter and number of names to be entered (members)
        int i=0;
        int members=3;
        String[] names = new String[members];
        //Input name
       if(i<members){i++;
          names[i]=JOptionPane.showInputDialog("What is your name?");}
       else{
       // Get the first name from a name string using split() instance
(non-static) method
            String[] nameArray0 = names[0].split(" ");
            String[] nameArray1 = names[1].split(" ");
            String[] nameArray2 = names[2].split(" ");
           // String[] nameArrayForPerson2 = person2NameInstance.split
(" ");

          // Get the lengths of strings using length() instance (non-
static) method
            int lengthFirstName0 = nameArray0[0].length();
            int lengthFirstName1 = nameArray1[0].length();
            int lengthFirstName2 = nameArray2[0].length();

          // Compare the lengths of the first names between person1
and person2
            if (lengthFirstName0 > lengthFirstName1){
                System.out.println(nameArray0[0] +
                              " has longer first name than " +
                              nameArray1[0]);
    }
            if(lengthFirstName1>lengthFirstName2){
                System.out.println(nameArray1[0]+" has longer first
name than "+nameArray2[0]);}
            else{System.out.println(nameArray2[0]+" has the longest
first name.");}

    }}}




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