• 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

Extracting numbers from from a user input and comparing it to

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i personally cannot get lines 22-26 to do what they are supposed to do. It is supposed to reverse the guess and random number (ex: 123 = 321). Im just looking for a little bit of help on those lines. thankyou.


 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The first line of the condition checks to see if the units and the tens digits are equal. The second line checks to see if the units digit are equal. This makes the second line moot, as any test that will pass the first line will also pass the second line.

The third line of the condition checks to see if the hundreds digit and higher are equal. The fourth line checks to see if the tens digit and higher are equal. This makes the third line moot, as any test that will pass the fourth line will also pass the third line.

And finally, to pass both the first and fourth lines, the two numbers must be the same. This makes the whole condition moot, as we know the numbers are not exactly equal, as it would not have arrived at this "else" clause if they were equal.

Henry
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, you would need a better way to check if one digit is in another number:

You would then have to call this method for each of the digits in your number:

This check will still fail though, if either the guess or the lotto has duplicate digits and there is a match like that. For instance, if the lotto number is 123 and the guess is 111, then you still have a problem - 1 is in the lotto number. Checking both ways (digitIsInNumber(lotto % 10, guess)) will also not solve this; just check with lotto 112 and guess 122.

You could try sorting the digits within the number, and then check if the sorted values are equal:

That brings us to one small flaw in your logic: you never check if the user input is in the right range.
 
Andrew Albers
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you very much for the help.
reply
    Bookmark Topic Watch Topic
  • New Topic