Results 1 to 2 of 2
- 02-26-2012, 06:55 AM #1
Member
- Join Date
- May 2010
- Posts
- 45
- Rep Power
- 0
- 02-26-2012, 07:10 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Re: Determine if string contains anything but only one letter
How do you know that?"AA" = true, "AAAAAAAAA" = true, "AAAXAAA" = False, "EKNFLGKGOKE" = False.
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
-
frequency of occurence of a letter in a string
By manish007g in forum New To JavaReplies: 4Last Post: 06-23-2011, 09:05 PM -
Preventing errors when typing a letter into a String
By doymand in forum New To JavaReplies: 5Last Post: 10-30-2010, 06:56 PM -
String is not accepting "*" letter, please help me to solve
By srisar in forum New To JavaReplies: 18Last Post: 07-12-2009, 05:47 PM -
the number of occurrences of each alphabetical letter in the string.
By masaka in forum New To JavaReplies: 20Last Post: 05-14-2008, 09:42 AM -
how to determine the primary key
By osval in forum JDBCReplies: 1Last Post: 08-07-2007, 02:31 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks