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 3 of 3

Thread: strings problem

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default strings problem

    HI, I have a problem to resolve and I don't know how to do it.
    The problem goes as follow: I have two strings. Each string is a sequence of letter.
    First, I have to return the sequence of letter representing the first string where is deleted the common prefix to both strings.
    For example: if I have the strings abcde and abcgh, it returns de, where abc is the common prefix.
    Second, I have to return the sequence of letter obtained by deleting all the letters that occurs more than one and keep all the first occurrence of these letters.
    For example: abddeggh would equal abdegh
    Third,I have to return the sequence of letter by keeping only the first occurrence of the letters in a first sequence of letter and delete all the letters that appear in a second sequence of letters.
    For example: asdfgghh and uioasf, would equal dgh.

    Can I get help to resolve these three problems please?


  2. #2
    Junior Member
    Join Date
    Mar 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: strings problem

    1. loop though both words at the same time. Once you encounter a letter that is different print out the substring of the first word.
    2. Loop through the string. Remember the last character. If the current character is the same as the last character do not print it.
    3. Easiest way, loop through each character of the first work. Loop through the second word, if the character appears do not print it.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: strings problem

    Quote Originally Posted by mperemsky View Post
    1. loop though both words at the same time. Once you encounter a letter that is different print out the substring of the first word.
    2. Loop through the string. Remember the last character. If the current character is the same as the last character do not print it.
    3. Easiest way, loop through each character of the first work. Loop through the second word, if the character appears do not print it.
    In 2, how do i remember the last character in a loop.
    In 1, how do I quit the loop after substring the first word

    Thanks for your help by the way

Similar Threads

  1. Having problem to stop reading strings
    By scsa316 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 18th, 2011, 11:24 AM
  2. Replies: 36
    Last Post: July 25th, 2011, 11:27 AM
  3. Strings
    By Leeds_Champion in forum Algorithms & Recursion
    Replies: 3
    Last Post: November 3rd, 2009, 10:09 PM
  4. Strings
    By BeSwift21 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 13th, 2009, 08:02 PM
  5. Replies: 2
    Last Post: June 19th, 2008, 04:58 AM