Results 1 to 4 of 4
- 07-10-2008, 06:09 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 20
- Rep Power
- 0
Trouble with a search hw problem.
This specific homework problem asks us to:
My answer: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.
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.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]; }
Does anyone kno another way of doing this?
- 07-10-2008, 08:31 PM #2
What do you get? Is it from the compiler or from exection?I get no information why it is not valid from the program/copiler
I'm confused. Does the program work? or not?when I test works
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.
- 07-10-2008, 08:54 PM #3
Member
- Join Date
- Jun 2008
- Posts
- 20
- Rep Power
- 0
It works when tested with print statements but the online hw submission thing does not provide any feedback at all--only, "invalid";
- 07-10-2008, 09:26 PM #4
Similar Threads
-
compiling trouble
By capacitator in forum CLDC and MIDPReplies: 4Last Post: 06-10-2008, 10:12 PM -
Problem with displaying search results from an array
By BHCluster in forum New To JavaReplies: 4Last Post: 04-24-2008, 03:34 AM -
Compile Trouble
By adelgado0723 in forum New To JavaReplies: 5Last Post: 04-21-2008, 02:02 AM -
Having trouble with array
By ice22 in forum New To JavaReplies: 3Last Post: 11-13-2007, 03:06 AM -
problem with recursive binary search program
By imran_khan in forum New To JavaReplies: 3Last Post: 08-02-2007, 03:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks