Results 1 to 4 of 4
  1. #1
    frasifrasi is offline Member
    Join Date
    Jun 2008
    Posts
    20
    Rep Power
    0

    Default Trouble with a search hw problem.

    This specific homework problem asks us to:
    Java Code:
     A String variable, fullName, contains a name in one of two formats:
    last name,first name (comma followed by a blank), or
    first namelast name (single blank)
     Extract the first name into the String variable firstName and the last name into the String variable lastName. 
    Assume the variables have been declared and fullName already initialized. 
    You may also declare any other necessary variables.
    My answer:

    Java Code:
    int a = fullName.indexOf(",");
    	    int b = fullName.indexOf(" ");
    	    
    	    if(a >= 0){
            String [] temp = null;
             temp = fullName.split("\\,");
    
            firstName = temp[1].trim();
            lastName = temp[0].trim();
            
            }
            
            else if(b >= 0){
            String [] temp = null;
             temp = fullName.split(" ");
    
            firstName = temp[0];
            lastName = temp[1];
            
            }
    Which, when I test works, but I get no information why it is not valid from the program/copiler. I am thinking there may be looking for a simpler solution.

    Does anyone kno another way of doing this?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default

    I get no information why it is not valid from the program/copiler
    What do you get? Is it from the compiler or from exection?
    when I test works
    I'm confused. Does the program work? or not?
    If not, what is wrong with what it does? Could you show the output and explain why it is wrong and what you'd like it to be.

    Puttnig comments in code to explain what & why are helpful for anyone to understand what you are trying to do.

  3. #3
    frasifrasi is offline Member
    Join Date
    Jun 2008
    Posts
    20
    Rep Power
    0

    Default

    It works when tested with print statements but the online hw submission thing does not provide any feedback at all--only, "invalid";

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default

    online hw submission
    Is hw a program that reads/reacts to your program and produces the response: invalid?

    To get any help you'll have to ask the admin person for the hw program. No idea here what that program wants.

Similar Threads

  1. compiling trouble
    By capacitator in forum CLDC and MIDP
    Replies: 4
    Last Post: 06-10-2008, 11:12 PM
  2. Problem with displaying search results from an array
    By BHCluster in forum New To Java
    Replies: 4
    Last Post: 04-24-2008, 04:34 AM
  3. Compile Trouble
    By adelgado0723 in forum New To Java
    Replies: 5
    Last Post: 04-21-2008, 03:02 AM
  4. Having trouble with array
    By ice22 in forum New To Java
    Replies: 3
    Last Post: 11-13-2007, 04:06 AM
  5. problem with recursive binary search program
    By imran_khan in forum New To Java
    Replies: 3
    Last Post: 08-02-2007, 04:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •