【发布时间】:2015-09-10 15:25:32
【问题描述】:
所以我正在制作一个用 10000 到 55555 的数字填充字符串的方法。这些数字在 6 位数字系统中。这意味着当我们有 10005 时,下一个数字是 10010,并且 11555 -> 12000。 在我填满字符串之后,我将遍历字符串并计算字符串中只有 2 个或更少相等数字的每个数字(或计算每个数字,并从计数中删除那些具有 3 个或更多相等数字的数字)。
我做了一个 for 循环,用所有数字填充字符串,但我不知道如何找到 3 og 更多相等数字的数字。 我猜我需要另一个带有 If 语句的 for 循环,但我只是想不通。试图同时使用 char 和 int 进行循环,但我显然做错了。
这是我目前所拥有的:
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;
}
}
有什么想法吗?
【问题讨论】:
标签: java string if-statement for-loop count