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

Thread: Help with counter controlled while loop please!

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help with counter controlled while loop please!

    Write program which reads two DNA sequences and then prints their Hamming distance.
    The Hamming distance is the number of one to one character mismatches between the two sequences.
    You are required to use a while counter controlled loop.

    Hint: Use the following methods from the String class: charAt( ), length( ).

    Example1
    Enter sequence 1:
    MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAA KKADRLAAEG
    Enter sequence 2:
    MTEITAAMVKELRESTGAGMMDMKNALSETNGDFDKAVQLLREKMLGKAA KKADMLAAEG
    Their Hamming distance is 3


    I know how do all of the basic setting up but I am confused on how to set up the counter controlled while loop so that it compares the two strings and counts how many differences there are. pleeeease help!


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Help with counter controlled while loop please!

    Could you post what code you have so far?

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Help with counter controlled while loop please!

    Do you know how to write a while loop? See - http://www.javaprogrammingforums.com...ava-loops.html
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  4. #4
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Help with counter controlled while loop please!

    int LOOPS_RUN = 0, MISMATCHES_FOUND = 0, LENGTH_OF_WORDS = word1.length(); // assumes their the same.. not sure if thats true or not.
    while(LOOPS_RUN < LENGTH_OF_WORDS)
    {
      if(word1.charAt(LOOPS_RUN) == word2.charAt(LOOPS_RUN))
      {
         LOOPS_RUN++;
      }else
      {
         MISMATCHES_FOUND++;
         LOOPS_RUN++;
      }
    }

    Their you go, your while loop, check if their the same and do stuff. You might need more, but this is your basic loop. I would of explained it, but it was easier to show you. Don't copy it directly, because its probably has errors .. just the idea.

  5. The Following User Says Thank You to Tjstretch For This Useful Post:

    rockout341 (March 29th, 2011)

Similar Threads

  1. Help With Counter
    By Catgroove in forum Java Theory & Questions
    Replies: 7
    Last Post: February 10th, 2011, 07:50 AM
  2. Dice Counter
    By Xxl0n3w01fxX in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 26th, 2011, 10:49 AM
  3. for loop and while loop problems
    By Pulse_Irl in forum Loops & Control Statements
    Replies: 4
    Last Post: May 3rd, 2010, 02:09 AM
  4. Odd Even Zero Counter?
    By velop in forum Java Theory & Questions
    Replies: 1
    Last Post: February 19th, 2010, 01:13 PM
  5. String counter
    By chkang0130 in forum Algorithms & Recursion
    Replies: 9
    Last Post: December 8th, 2009, 10:56 AM