java 中数字的问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 15:11:08
如何用Java打印出10000到99999中同时出现三个一样数字的数?比如:12333、52535、98788等。

代码实现如下:

public class GetNumbers {
public static boolean check(Integer num) {
String str = num.toString();
int size = str.length();
if (size < 3) {
return false;
}
int tempNum;
int curNum;
int count = 0;
for (int i = 0; i < size - 2; i++) {
tempNum = Integer.parseInt(str.substring(i, i + 1));
for (int j = 0; j < size; j++) {
if (j == size - 1) {
curNum = Integer.parseInt(str.substring(j));
} else {
curNum = Integer.parseInt(str.substring(j, j + 1));
}
if (tempNum == curNum) {
count++;
}
}
if (count == 3) {
return true;
}
count = 0;
}

return false;

}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int i = 10000; i <= 99999; i++) {