Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: String problem

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post String problem

    removed for a reason
    Last edited by javabeg123; December 6th, 2011 at 08:54 PM.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: String problem

    if(length> maxLength)
    longName = name;

    You should also be setting max length to the length of the new longName perhaps....
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: String problem

    im very new to programming
    can you explain more ?

  4. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: String problem

    if maxLength is 0, you never update maxLength from 0. So all city names will be longer than zero, thus the last name you enter will also be returned. You need maxLength to change each time you find a name longer than maxLength.

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  5. #5
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Stressed
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: String problem

    you need to add:

    maxLength = longName.length();

    place this after longName = name;

  6. The Following User Says Thank You to Herah For This Useful Post:

    javabeg123 (December 6th, 2011)

  7. #6
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: String problem

    Herah,

    We are not overlykeen on spoonfeeding solutions here, we prefer to guide towards the solution, but not provide the solution.

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  8. #7
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: String problem

    Quote Originally Posted by Herah View Post
    you need to add:

    maxLength = longName.length();

    place this after longName = name;
    OMG! THANK YOU!
    U SAVED MY LIFE !!
    THANK ALOT

Similar Threads

  1. string==null or string.equals(null) problem
    By csharp100 in forum What's Wrong With My Code?
    Replies: 31
    Last Post: November 4th, 2011, 09:17 AM
  2. Problem with String replace and CharSequence
    By Calii in forum Java Theory & Questions
    Replies: 3
    Last Post: October 4th, 2011, 08:32 PM
  3. string tabbing problem
    By rhalliwell1 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: March 9th, 2011, 01:47 PM
  4. array/string problem
    By RSYR in forum Collections and Generics
    Replies: 1
    Last Post: December 18th, 2009, 10:24 PM
  5. String and int problem in swing program
    By duckman in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 21st, 2009, 03:28 AM