我想知道如何创建一个循环,打印 200000 - 900000 之间的所有数字并删除所有数字,例如 222244。
到目前为止,这就是我所拥有的:
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class alg {
public void algorithm(){
}
public static void main(String []args){
PrintWriter file = null;
try {
file = new PrintWriter("output.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int x;
for (x = 200000; x < 900000; x++){
file.println(x);
}
}
file.close();
}
最佳答案
// return true if integer has 4 or more of same digit, otherwise false
static boolean check4(int i) {
int[] charCounts = new int[10];
for (char c : String.valueOf(i).toCharArray()) {
if (++charCounts[c-'0'] == 4) return true;
}
return false;
}
关于Java Loop - 删除具有 4 个或更多相同数字的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29220346/