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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Liutauras Vilda
• Junilu Lacar
• Jeanne Boyarsky
• Bear Bibeault
Sheriffs:
• Knute Snortum
• Tim Cooke
• Devaka Cooray
Saloon Keepers:
• Ron McLeod
• Stephan van Hulst
• Tim Moores
• Tim Holloway
• Carey Brown
Bartenders:
• Piet Souris
• Frits Walraven
• Ganesh Patekar

How do you match numbers on Android with Java?

Greenhorn
Posts: 3
Hello,
I'm trying to develop a java project in Android Studio.I want to produce a 5-digit random number.To estimate this number, the user will enter a 5 digit number.According to the number entered, the program captures a match in any digit of the number entered by the user with the random generated number "matched a Digit to the screen."I want him to print it.
To give an example:
Let be the generated random number 53297. Let the number that the user enters into the screen to guess be 51648. In this case only five figures matched "one digit" on the screen because it was common."I'm developing a project that I want him to write.But I don't know exactly how to do this match-up thing. I'm new to this area and I'm trying to improve myself.You can help I would be glad about that.Thanks in advance.

Rancher
Posts: 3441
33
Can you treat the number as a sequence of characters ?  Then sort the sequence making it easier to compare the two sequences.
Or use a 10 slot array to hold the counts of the number of occurrences of each of the 10 possible values a digit could have.
For example 22344 would give this as the array's contents: 0,0,2,1,2,0,0,0,0,0,0

George Georgy
Greenhorn
Posts: 3

Norm Radder wrote:Can you treat the number as a sequence of characters ?  Then sort the sequence making it easier to compare the two sequences.
Or use a 10 slot array to hold the counts of the number of occurrences of each of the 10 possible values a digit could have.
For example 22344 would give this as the array's contents: 0,0,2,1,2,0,0,0,0,0,0

How do I create this sequence? Can you explain the subject a little more? I'm new to this field, and I don't know some things, but I'm trying to learn. Thanks

Rancher
Posts: 3441
33

How do I create this sequence?

To get a sequence of characters from an int value, convert it to a String using the Integer class's toString method.

Marshal
Posts: 65814
250
Would you want a String in the first place? I remember when I was beginning I was given an exercise to print the individual digits in an int backwards, which was done with a combination of a while loop and the / and % operators. You can alternatively use those digits as indices to increment the values in your array.

Not an Android problem: moving to a Java forum.

 Won't you be my neighbor? - Fred Rogers. tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton