Results 1 to 2 of 2
  1. #1
    reverton is offline Member
    Join Date
    Apr 2013
    Rep Power

    Default Count number of different letters in strings

    I need to count how many different letter in same position there are between 2 strings. For example: Abcd and ABCF would be 1.

    Java Code:
        	int counter=0;
        	for(int i =0; i<sequence2.length();++i){
            return counter;

    My code is not passing the test it is supposed to and I can't figure out what's wrong with it..
    Last edited by reverton; 04-28-2013 at 12:48 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Count number of different letters in strings

    A minor nitpick: you are converting two Strings to lowercase over and over again in the body of that loop; better do this:

    Java Code:
    String a= sequence1.toLowercase();
    String b= sequence2.toLowercase();
    int counter= 0;
    for (int i= 0; i < a.length(); i++)
       if (a.charAt(i) != b.charAt(i)) counter++;
    return counter;
    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Compare letters of 2 strings
    By reverton in forum New To Java
    Replies: 9
    Last Post: 04-28-2013, 08:40 AM
  2. count every 45 records and prfix the count number
    By dkr786 in forum New To Java
    Replies: 8
    Last Post: 02-15-2013, 08:31 PM
  3. Replies: 8
    Last Post: 01-21-2012, 02:14 AM
  4. changing letters in strings
    By dienesh77 in forum New To Java
    Replies: 8
    Last Post: 02-17-2011, 02:56 PM
  5. text Strings to produce letters
    By dc2acgsr99 in forum New To Java
    Replies: 7
    Last Post: 01-29-2008, 09:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts