• 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

 
Swaroop Kunduru
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
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • 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.
 
Dieter Quickfend
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: 56518
172
  • 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!