• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

checks words for dupledromity

 
Ranch Hand
Posts: 48
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.




 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't think you really need two variables 'i' and 'j'. you really only need one.
 
Liutauras Vilda
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic