So I am making a method that fills up a String with numbers from 10000 to 55555. The numbers are in the 6 number system. Meaning that when we have 10005, next number is 10010, and 11555 -> 12000. After I have filled up the String, I shall loop through the String and count every number in the String which has only 2 or less equal digits (or count every number ,and remove those with 3 and more equal digits from the count).
I made a for-loop that fills up the String with all the numbers, but I don't figure out how to find the numbers with 3 og more equal digits. I'll guess I need another for-loop with an If-statement, but I just don't figure it out. Tried to use both char and int for looping through, but I obviously do something wrong.
This is what I have so far:
public class TestProgram {
public static void main(String... args)
{
System.out.println(membersnumbers());
}
public static int membersnumbers()
{
int count = 0;
for (int i = 1296; i < 7776; i++) //fills the String with numbers from 1000 to 5555
{ //without numbers over 6
String number = Integer.toString(i,6); //making the String and fills it with numbers
for (<run through all the numbers>)
{
if (<number has less than 3 equal digits )
{
count++;
}
}
}
return count;
}
}
Any ideas?
Aucun commentaire:
Enregistrer un commentaire