Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-08-2008, 05:57 PM
Member
 
Join Date: Jun 2008
Posts: 20
frasifrasi is on a distinguished road
How do I do this.
This a homework problem, but I am stuck, I don't know how to fix it - it just says the result is wrong.

An array of Strings, names, has been declared and initialized. Write the statements needed to determine whether any of the the array elements are null or refer to the empty String. Set the variable hasEmpty to true if any elements are null or empty-- otherwise set it to false.

My ans:

hasEmpty = false;
for(int i = 0; i < names.length; i++){
if(names[i] == null){ hasEmpty = true;}

}


Can anyone help?

Thanks!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-08-2008, 06:06 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SW MO, USA
Posts: 933
Norm is on a distinguished road
it just says the result is wrong.
What does that mean? Do you have an error message that you could copy and post here???

There is a problem in your code that it is only checking for a null value and not for the case where the String value = "" (an empty string). You need to add a test for that. Remember that a string variable is an object and that to access/test the value of an object you must use a method. Clue: Read the API doc for String to see what method(s) would test for equality.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-08-2008, 10:06 PM
Member
 
Join Date: Jun 2008
Posts: 20
frasifrasi is on a distinguished road
Norm, that was very helpful, thank you. I was able fo fix it.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-09-2008, 09:55 AM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 282
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
Mark it as SOLVED...
__________________
To finish sooner, take your own time....
Nivedithaaaa
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 04:23 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org