This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the logic I have to apply to get this result. Unable to find the solution.  RSS feed

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to write a Static method that takes an int as input, and returns true if all the digits in the base 10 representation of that number are unique.
boolean AllDigitsUnique(int value)
Example:
AllDigitsUnique(48778584) returns false
AllDigitsUnique(17308459) returns true
 
Marshal
Posts: 58421
178
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by turning your computer off and working out how you would do it on paper.
 
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simply put: int to string, string to char array, compare or put in collection that doesn't accept duplicates.
 
Campbell Ritchie
Marshal
Posts: 58421
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is one way to do it, but you don't need to turn the int to a String; you can separate the individual digits with different operations.

OP: How far have you got? What did you end up writing on your paper?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!