Jorge,
 
do this and see what happens.
 
// i am correcting where i feel logic is wrong.
//you are not reading 3 first name so dont make it an array it is regular 
string.
 
 //String []firstName = new String [3] ;
 
 String firstName = "";

//now it is not array any more so do this.
//  firstName[i] = fullName[i].split(" ");
 
 firstName = fullName[i].split(" ");
 
Now see what happens.
 
--Ravi.Halli

--- On Wed, 12/3/08, Jorge Ortalli <[EMAIL PROTECTED]> wrote:

From: Jorge Ortalli <[EMAIL PROTECTED]>
Subject: [java programming] Re: LAB 1036 : Java Array : How to use Split 
Function for Array using Looping Structure
To: [EMAIL PROTECTED]
Cc: [email protected]
Date: Wednesday, December 3, 2008, 1:14 AM


2008/11/24 Ravi NS <[EMAIL PROTECTED]>


Hi all,

This been a Month and I'm Stuck with this function named Split.

split Defines
The array of strings computed by  splitting this string around matches of the 
given regular expression

Return Type is String which is Split



Here is the Code.
******************************************************************************************************************************
public class JavaArrayProject {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        String []fullName = new String [3];
             
        //  Input for String for FULL NAME
        
        for ( int i=1; i<=3 ; i++ )
        {    fullName [i] = JOptionPane.showInputDialog("Please Enter Family 
Member "+
                    i + " First and Last Name ");
        }
        
        // Split Function for Extracting First Name
        String []firstName = new String [3] ;
        
        for (int i=1 ;i<=3 ; i++ )
          firstName[i] = fullName[i].split(" ");   
        
        
******************************************************************************************************************************

I'm getting a Error in the last line. My logic on that statement is wrong. IDE 
gives me "incompatible types" and it says 
  found : java.lang.string[]
  required : java.lang.string

My thoughts are like this..
Full Name  = Ravi Nazre
So First Name  is Ravi and Last Name is Nazre.

here fullName= Ravi Nazre
if i Use
firstName[ ] = fullName[].split(" ");

It should store First Name


I'm Still wondering what needs to be done here. I want to use Looping Structure 
for Scalability.
Please help






Hi all,
 I thought a code such that the only fixed (constant) value is the number of 
members to enter. It works but I am not sure if I am using correctly the 
initialization of the multidimensional array. 

In a first step I Initialize the first dimension of the array:

            int numberOfMembers = 3;
            
            String[][] arrayOfNames= new String[numberOfMembers][];            

In a second stage I ask for the full names of each member (up to 
numberOfMembers) and then I initialize the second dimension of the 
multidimensional array (and here is where I am not sure if it is valid to do): 

            for (int i= 0; i< arrayOfNames.length; i++) {                
                arrayOfNames[i] = new 
String(JOptionPane.showInputDialog(String.format("Member #%d, enter your full 
name, please", i+1))).split(" ");                
            }            

In a third stage to find the owner of the longest first name:

            int longestFirstNameOwner= 0;
            int longestFirstNameLength= 0;
            for (int i= 0; i<arrayOfNames.length; i++){
                if (arrayOfNames[i].length > 0) {
                    if (arrayOfNames[i][0].length() > longestFirstNameLength){
                        longestFirstNameLength= arrayOfNames[i][0].length();
                        longestFirstNameOwner= i;
                    }
                }                    
            }

This code works well. If numberOfMembers  where a parameter it will be possible 
to find the longest first name of any number of people without modifying this 
code. But I still have a doubt, if it is valid to initialize the 
miltidimensional array in the way I did.

Thanks averibody

-- 
Jorge Ortalli





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