Results 1 to 2 of 2
  1. #1
    artemis_r2 is offline Member
    Join Date
    Nov 2007
    Posts
    1
    Rep Power
    0

    Default adjacent repeating letters

    I d like to ask whether anybody knows a simple way to calculate the letters of a phrase and the adjacent repeating letters till '#' occurs,,,

    For example:
    Hello Harry! [Goodmorning]#

    Letters : 21
    Adjacent repeating letters: 3

    Thanx a lot!!!:) :) :)

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    public class AdjacentCount {
        public static void main(String[] args) {
            String text = "Hello Harry! [Goodmorning]#";
            int length = text.length();
            int count = 0;
            int pos = 0;
            while(pos < length-1) {
                if(text.charAt(pos) == text.charAt(pos+1)) {
                    System.out.println("found match " + text.charAt(pos) +
                                       " at " + pos + " and " + (pos+1));
                    count++;
                }
                pos++;
            }
            System.out.println("count = " + count);
        }
    }

Similar Threads

  1. text Strings to produce letters
    By dc2acgsr99 in forum New To Java
    Replies: 7
    Last Post: 01-29-2008, 08:08 PM
  2. need block letters??
    By dc2acgsr99 in forum New To Java
    Replies: 16
    Last Post: 01-29-2008, 08:31 AM
  3. validating a string for numbers and letters?
    By lockmac in forum New To Java
    Replies: 1
    Last Post: 08-09-2007, 09:17 AM

Posting Permissions

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