Akimbas Akimbasas

Ranch Hand

Posts: 32

1

posted 4 years ago

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.

When I run this, it says that even the number with equivalent digits does not have the same digits.

Akimbas Akimbasas

Ranch Hand

Posts: 32

1

posted 4 years ago

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.

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

Campbell Ritchie

Marshal

Posts: 56598

172

Campbell Ritchie

Marshal

Posts: 56598

172

Akimbas Akimbasas

Ranch Hand

Posts: 32

1

It is sorta covered in the JavaRanch Style Guide. |