62,628
社区成员
发帖
与我相关
我的任务
分享
[/quote]
答完题我才发现看走眼了,楼主要的的确是2楼出的结果,sorry。

package te;
import java.util.Scanner;
public class b {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int aa=11;
for(int i=10;i<=n;i++){
if(i>=aa*9){
aa=aa*10+1;
}
if(i%aa==0){
System.out.println(i);
}
}
}
}
这个正解。。 public static void main(String[] args) throws Exception {
Map<Integer, Integer> map = new HashedMap();
for (int i = 10; i < 1000; i++) {
Integer key = String.valueOf(i).length();
Integer divisor = null;
if(map.containsKey(key)){
divisor = map.get(key);
}else{
char[] data = new char[key];
Arrays.fill(data, '1');
divisor = Integer.parseInt(new String(data));
map.put(key, divisor);
}
if(i % divisor == 0){
System.out.println(i);
}
}
}
欢迎光临我的博客
http://happyshome.cn public static void main(final String[] args){
for(int i = 10; i < 1000; i++){
char[] chars = Integer.toString(i).toCharArray();
if(CharBuffer.wrap(chars).chars().distinct().count() == 1)
System.out.printf("%d%n", i);
}
}
结果是:
11
22
33
44
55
66
77
88
99
111
222
333
444
555
666
777
888
999