• Post Reply Bookmark Topic Watch Topic
  • New Topic

checks words for dupledromity  RSS feed

 
shweta patiljadhav
Ranch Hand
Posts: 48
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A dupledrome is a word that contains only double letters, like “llaammaa” or “ssaabb”. I conjecture that there are no dupledromes in common English use. To test that conjecture, I would like a program that reads words from the dictionary one at a time and checks them for dupledromity.
Write a method called isDupledrome that takes a String and returns a boolean indicating whether the word is a dupledrome.

I have written this code, where int i will count characters at odd number and int j will count characters at even number and comparing them will give answer wether the word is dupledrome or not..please complete this code.




 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi shweta patiljadhav,

Some comments from my perspective:
1. Class names suppose to start with Upper case.
2. You have been asked to write the method named "isDupledrome". I don't see such a named method. Method return type also incorrect.
3. If you decided solve this way by comparing even an odd characters, might you'd need to check if length is an even number, if not, then you straight know it is not "dupledrome".

Anyway, when you tried to run your code, whats happened? Did you get what you expected? Any syntax errors? Unexpected answer? Any other issues?

I'd solve this problem in different way, but lets see what others think.
 
Campbell Ritchie
Marshal
Posts: 56527
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

I don't think the method you have will work. What you are looking for is where the 1st letter equals the 2nd, the 3rd equals the 4th, etc. I think you are going to have to delete the entire method and get a piece of paper and write how you are going to find whether you have pairs of letters throughout the word. Only when you have worked out the logic should you think aboiut writing the code.

I am pretty sure the Scrabble chappies would find some dupledromes for you
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pretty sure the Scrabble chappies would find some dupledromes for you


The closest I could find besides double letters (e.g., "Oo") were Aarrgh and Eellike.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't think you really need two variables 'i' and 'j'. you really only need one.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shweta patiljadhav,

Once again, how you could solve that:

1. Method suppose to take a String as an argument and return boolean value.
2. First, I'd suggest you to check, if word has even number of characters, if not - it is not dupledrome, so no extra checks needed.
3. You need to check 1st character with 2nd, then 3rd with 4th and so on. Bear in mind, that 1st character could be an Upper case, and second lower case. So, 'O' and 'o' in terms of char type wouldn't be equal. This part you could solve by taking string parameter and making it lower case.
4. So to check, each iteration you suppose to check current character with a one ahead. If these are equal, then increment counter by n times, in order to check 3rd with 4th character, then 5th with 6th and so on.
5. If any of these pairs doesn't match (when you checking on the fly), return false straight away without checking anything else. And if all loop goes from the beginning of the string to the end without returning false, then, after loop block ends - return true.

Hope it helps.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!