Results 1 to 2 of 2
  1. #1
    atomant is offline Member
    Join Date
    May 2010
    Rep Power

    Default Determine if string contains anything but only one letter

    I want to determine if a string contains anything but only one certain character. For example, "AA" = true, "AAAAAAAAA" = true, "AAAXAAA" = False, "EKNFLGKGOKE" = False. I'm not sure how to easily do this.


  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

    Default Re: Determine if string contains anything but only one letter

    "AA" = true, "AAAAAAAAA" = true, "AAAXAAA" = False, "EKNFLGKGOKE" = False.
    How do you know that?

    What I mean is what thought process told you that "AAAAAAAAA" was true while "AAAXAAA" was false? Figuring out how you decided that is the first (and biggest) step towards writing code to do the same thing. Our eyes are very good at detecting patterns (and especially breaks in patterns) - they act quickly and beneath conscious awareness - so we are not really given a chance to be reflective about how we solve problems like this.

    One way of achieving this awareness is to imagine you can only see one character at a time. For instance suppose people entered your room through a door on the left carrying a letter on a cardboard sign and exited again through a door on the right. You knew in advance you were going to be asked if all the people were displaying the same character. What would you do while the people came and went to ensure you could answer the question? Could you answer it "early": ie would you have to pay attention to all the people?


    After that it's a case of looking at the String API, and reviewing what you know about loops and the "break" keyword. But think about the problem first! In "slow motion" as suggested above or some other way. You need a precise and comprehensive description of the process (== "algorithm") before you can start to write code.

Similar Threads

  1. frequency of occurence of a letter in a string
    By manish007g in forum New To Java
    Replies: 4
    Last Post: 06-23-2011, 09:05 PM
  2. Replies: 5
    Last Post: 10-30-2010, 06:56 PM
  3. Replies: 18
    Last Post: 07-12-2009, 05:47 PM
  4. Replies: 20
    Last Post: 05-14-2008, 09:42 AM
  5. how to determine the primary key
    By osval in forum JDBC
    Replies: 1
    Last Post: 08-07-2007, 02:31 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