• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding out if all the digits are equivalent in three digit number  RSS feed

 
Akimbas Akimbasas
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I was asked to write a program that finds out if the digits in the three-digit number are the same. I thought a bit about it, wrote some java stuff about it, and it seems I need some tip or somethin.


When I run this, it says that even the number with equivalent digits does not have the same digits.
 
Niraj Jha
Ranch Hand
Posts: 63
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[mg]edited out solution
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Niraj,

Unfortunately I edited out your (correct) solution.
To quote from the top of this forum
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.

Hope you understand.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akimbas Akimbasas wrote:..and it seems I need some tip or somethin.


Welcome to the Ranch.

Here's your tip

Print out the values for
x % 100, x % 10, x % 1 and I promise you will be surprised
 
Niraj Jha
Ranch Hand
Posts: 63
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure @Maneesh.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, figure out how to get individual digits correctly.
Then, just compare them.
 
Akimbas Akimbasas
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the feeling that the x % 1 didn't want to cooperate, but it turns out that x % 100 is wrong as well . I picked the number 222 and I got 22, 2, 0.

So I think is safe to assume that the middle number will always be right. But how about the first and the last? Simple division ? I get 2.22 if I divide by 100 but if they're integer numbers, so it should be rounded up to 2. So only the last one remains, hmm. Any more tips? Modulus and simple division doesn't seem to get me the last 2.
 
Johan Fourie
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use modulus and simple division together. Hope this helps.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If by middle number you mean 3 in 234, then no, it isn't right. Try…and see what happens.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You most certainly can get the individual digits with a combination of remainder and simple division.
 
Akimbas Akimbasas
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorted it out it seems, it works without any problems. Thank you for your help, guys, I will look forward to ask for more tips. :p


Welcome to the Ranch.


Glad to be here.
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you have to complete this mathematically, this problem would be most easily solved by turning the integer into a String.

Edit: I see now that you've completed the assignment. Good job
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!